416 if (error)
417 break;
418 }
419 return (error);
420 }
421
422 offset_t zfs_read_chunk_size = 1024 * 1024; /* Tunable */
423
424 /*
425 * Read bytes from specified file into supplied buffer.
426 *
427 * IN: vp - vnode of file to be read from.
428 * uio - structure supplying read location, range info,
429 * and return buffer.
430 * ioflag - SYNC flags; used to provide FRSYNC semantics.
431 * cr - credentials of caller.
432 * ct - caller context
433 *
434 * OUT: uio - updated offset and range, buffer filled.
435 *
436 * RETURN: 0 if success
437 * error code if failure
438 *
439 * Side Effects:
440 * vp - atime updated if byte count > 0
441 */
442 /* ARGSUSED */
443 static int
444 zfs_read(vnode_t *vp, uio_t *uio, int ioflag, cred_t *cr, caller_context_t *ct)
445 {
446 znode_t *zp = VTOZ(vp);
447 zfsvfs_t *zfsvfs = zp->z_zfsvfs;
448 objset_t *os;
449 ssize_t n, nbytes;
450 int error = 0;
451 rl_t *rl;
452 xuio_t *xuio = NULL;
453
454 ZFS_ENTER(zfsvfs);
455 ZFS_VERIFY_ZP(zp);
456 os = zfsvfs->z_os;
457
553 error = SET_ERROR(EIO);
554 break;
555 }
556
557 n -= nbytes;
558 }
559 out:
560 zfs_range_unlock(rl);
561
562 ZFS_ACCESSTIME_STAMP(zfsvfs, zp);
563 ZFS_EXIT(zfsvfs);
564 return (error);
565 }
566
567 /*
568 * Write the bytes to a file.
569 *
570 * IN: vp - vnode of file to be written to.
571 * uio - structure supplying write location, range info,
572 * and data buffer.
573 * ioflag - FAPPEND flag set if in append mode.
574 * cr - credentials of caller.
575 * ct - caller context (NFS/CIFS fem monitor only)
576 *
577 * OUT: uio - updated offset and range.
578 *
579 * RETURN: 0 if success
580 * error code if failure
581 *
582 * Timestamps:
583 * vp - ctime|mtime updated if byte count > 0
584 */
585
586 /* ARGSUSED */
587 static int
588 zfs_write(vnode_t *vp, uio_t *uio, int ioflag, cred_t *cr, caller_context_t *ct)
589 {
590 znode_t *zp = VTOZ(vp);
591 rlim64_t limit = uio->uio_llimit;
592 ssize_t start_resid = uio->uio_resid;
593 ssize_t tx_bytes;
594 uint64_t end_size;
595 dmu_tx_t *tx;
596 zfsvfs_t *zfsvfs = zp->z_zfsvfs;
597 zilog_t *zilog;
598 offset_t woff;
599 ssize_t n, nbytes;
600 rl_t *rl;
1131 return (error);
1132 }
1133
1134
1135 /*
1136 * Lookup an entry in a directory, or an extended attribute directory.
1137 * If it exists, return a held vnode reference for it.
1138 *
1139 * IN: dvp - vnode of directory to search.
1140 * nm - name of entry to lookup.
1141 * pnp - full pathname to lookup [UNUSED].
1142 * flags - LOOKUP_XATTR set if looking for an attribute.
1143 * rdir - root directory vnode [UNUSED].
1144 * cr - credentials of caller.
1145 * ct - caller context
1146 * direntflags - directory lookup flags
1147 * realpnp - returned pathname.
1148 *
1149 * OUT: vpp - vnode of located entry, NULL if not found.
1150 *
1151 * RETURN: 0 if success
1152 * error code if failure
1153 *
1154 * Timestamps:
1155 * NA
1156 */
1157 /* ARGSUSED */
1158 static int
1159 zfs_lookup(vnode_t *dvp, char *nm, vnode_t **vpp, struct pathname *pnp,
1160 int flags, vnode_t *rdir, cred_t *cr, caller_context_t *ct,
1161 int *direntflags, pathname_t *realpnp)
1162 {
1163 znode_t *zdp = VTOZ(dvp);
1164 zfsvfs_t *zfsvfs = zdp->z_zfsvfs;
1165 int error = 0;
1166
1167 /* fast path */
1168 if (!(flags & (LOOKUP_XATTR | FIGNORECASE))) {
1169
1170 if (dvp->v_type != VDIR) {
1171 return (SET_ERROR(ENOTDIR));
1172 } else if (zdp->z_sa_hdl == NULL) {
1273 return (error);
1274 }
1275
1276 /*
1277 * Attempt to create a new entry in a directory. If the entry
1278 * already exists, truncate the file if permissible, else return
1279 * an error. Return the vp of the created or trunc'd file.
1280 *
1281 * IN: dvp - vnode of directory to put new file entry in.
1282 * name - name of new file entry.
1283 * vap - attributes of new file.
1284 * excl - flag indicating exclusive or non-exclusive mode.
1285 * mode - mode to open file with.
1286 * cr - credentials of caller.
1287 * flag - large file flag [UNUSED].
1288 * ct - caller context
1289 * vsecp - ACL to be set
1290 *
1291 * OUT: vpp - vnode of created or trunc'd entry.
1292 *
1293 * RETURN: 0 if success
1294 * error code if failure
1295 *
1296 * Timestamps:
1297 * dvp - ctime|mtime updated if new entry created
1298 * vp - ctime|mtime always, atime if new
1299 */
1300
1301 /* ARGSUSED */
1302 static int
1303 zfs_create(vnode_t *dvp, char *name, vattr_t *vap, vcexcl_t excl,
1304 int mode, vnode_t **vpp, cred_t *cr, int flag, caller_context_t *ct,
1305 vsecattr_t *vsecp)
1306 {
1307 znode_t *zp, *dzp = VTOZ(dvp);
1308 zfsvfs_t *zfsvfs = dzp->z_zfsvfs;
1309 zilog_t *zilog;
1310 objset_t *os;
1311 zfs_dirlock_t *dl;
1312 dmu_tx_t *tx;
1313 int error;
1314 ksid_t *ksid;
1524 *vpp = ZTOV(zp);
1525 error = specvp_check(vpp, cr);
1526 }
1527
1528 if (zfsvfs->z_os->os_sync == ZFS_SYNC_ALWAYS)
1529 zil_commit(zilog, 0);
1530
1531 ZFS_EXIT(zfsvfs);
1532 return (error);
1533 }
1534
1535 /*
1536 * Remove an entry from a directory.
1537 *
1538 * IN: dvp - vnode of directory to remove entry from.
1539 * name - name of entry to remove.
1540 * cr - credentials of caller.
1541 * ct - caller context
1542 * flags - case flags
1543 *
1544 * RETURN: 0 if success
1545 * error code if failure
1546 *
1547 * Timestamps:
1548 * dvp - ctime|mtime
1549 * vp - ctime (if nlink > 0)
1550 */
1551
1552 uint64_t null_xattr = 0;
1553
1554 /*ARGSUSED*/
1555 static int
1556 zfs_remove(vnode_t *dvp, char *name, cred_t *cr, caller_context_t *ct,
1557 int flags)
1558 {
1559 znode_t *zp, *dzp = VTOZ(dvp);
1560 znode_t *xzp;
1561 vnode_t *vp;
1562 zfsvfs_t *zfsvfs = dzp->z_zfsvfs;
1563 zilog_t *zilog;
1564 uint64_t acl_obj, xattr_obj;
1565 uint64_t xattr_obj_unlinked = 0;
1755 VN_RELE(vp);
1756 if (xzp)
1757 VN_RELE(ZTOV(xzp));
1758
1759 if (zfsvfs->z_os->os_sync == ZFS_SYNC_ALWAYS)
1760 zil_commit(zilog, 0);
1761
1762 ZFS_EXIT(zfsvfs);
1763 return (error);
1764 }
1765
1766 /*
1767 * Create a new directory and insert it into dvp using the name
1768 * provided. Return a pointer to the inserted directory.
1769 *
1770 * IN: dvp - vnode of directory to add subdir to.
1771 * dirname - name of new directory.
1772 * vap - attributes of new directory.
1773 * cr - credentials of caller.
1774 * ct - caller context
1775 * vsecp - ACL to be set
1776 *
1777 * OUT: vpp - vnode of created directory.
1778 *
1779 * RETURN: 0 if success
1780 * error code if failure
1781 *
1782 * Timestamps:
1783 * dvp - ctime|mtime updated
1784 * vp - ctime|mtime|atime updated
1785 */
1786 /*ARGSUSED*/
1787 static int
1788 zfs_mkdir(vnode_t *dvp, char *dirname, vattr_t *vap, vnode_t **vpp, cred_t *cr,
1789 caller_context_t *ct, int flags, vsecattr_t *vsecp)
1790 {
1791 znode_t *zp, *dzp = VTOZ(dvp);
1792 zfsvfs_t *zfsvfs = dzp->z_zfsvfs;
1793 zilog_t *zilog;
1794 zfs_dirlock_t *dl;
1795 uint64_t txtype;
1796 dmu_tx_t *tx;
1797 int error;
1798 int zf = ZNEW;
1799 ksid_t *ksid;
1800 uid_t uid;
1940
1941 if (zfsvfs->z_os->os_sync == ZFS_SYNC_ALWAYS)
1942 zil_commit(zilog, 0);
1943
1944 ZFS_EXIT(zfsvfs);
1945 return (0);
1946 }
1947
1948 /*
1949 * Remove a directory subdir entry. If the current working
1950 * directory is the same as the subdir to be removed, the
1951 * remove will fail.
1952 *
1953 * IN: dvp - vnode of directory to remove from.
1954 * name - name of directory to be removed.
1955 * cwd - vnode of current working directory.
1956 * cr - credentials of caller.
1957 * ct - caller context
1958 * flags - case flags
1959 *
1960 * RETURN: 0 if success
1961 * error code if failure
1962 *
1963 * Timestamps:
1964 * dvp - ctime|mtime updated
1965 */
1966 /*ARGSUSED*/
1967 static int
1968 zfs_rmdir(vnode_t *dvp, char *name, vnode_t *cwd, cred_t *cr,
1969 caller_context_t *ct, int flags)
1970 {
1971 znode_t *dzp = VTOZ(dvp);
1972 znode_t *zp;
1973 vnode_t *vp;
1974 zfsvfs_t *zfsvfs = dzp->z_zfsvfs;
1975 zilog_t *zilog;
1976 zfs_dirlock_t *dl;
1977 dmu_tx_t *tx;
1978 int error;
1979 int zflg = ZEXISTS;
1980
1981 ZFS_ENTER(zfsvfs);
2059
2060 dmu_tx_commit(tx);
2061
2062 rw_exit(&zp->z_parent_lock);
2063 rw_exit(&zp->z_name_lock);
2064 out:
2065 zfs_dirent_unlock(dl);
2066
2067 VN_RELE(vp);
2068
2069 if (zfsvfs->z_os->os_sync == ZFS_SYNC_ALWAYS)
2070 zil_commit(zilog, 0);
2071
2072 ZFS_EXIT(zfsvfs);
2073 return (error);
2074 }
2075
2076 /*
2077 * Read as many directory entries as will fit into the provided
2078 * buffer from the given directory cursor position (specified in
2079 * the uio structure.
2080 *
2081 * IN: vp - vnode of directory to read.
2082 * uio - structure supplying read location, range info,
2083 * and return buffer.
2084 * cr - credentials of caller.
2085 * ct - caller context
2086 * flags - case flags
2087 *
2088 * OUT: uio - updated offset and range, buffer filled.
2089 * eofp - set to true if end-of-file detected.
2090 *
2091 * RETURN: 0 if success
2092 * error code if failure
2093 *
2094 * Timestamps:
2095 * vp - atime updated
2096 *
2097 * Note that the low 4 bits of the cookie returned by zap is always zero.
2098 * This allows us to use the low range for "special" directory entries:
2099 * We use 0 for '.', and 1 for '..'. If this is the root of the filesystem,
2100 * we use the offset 2 for the '.zfs' directory.
2101 */
2102 /* ARGSUSED */
2103 static int
2104 zfs_readdir(vnode_t *vp, uio_t *uio, cred_t *cr, int *eofp,
2105 caller_context_t *ct, int flags)
2106 {
2107 znode_t *zp = VTOZ(vp);
2108 iovec_t *iovp;
2109 edirent_t *eodp;
2110 dirent64_t *odp;
2111 zfsvfs_t *zfsvfs = zp->z_zfsvfs;
2112 objset_t *os;
2391 zil_commit(zfsvfs->z_log, zp->z_id);
2392 ZFS_EXIT(zfsvfs);
2393 }
2394 return (0);
2395 }
2396
2397
2398 /*
2399 * Get the requested file attributes and place them in the provided
2400 * vattr structure.
2401 *
2402 * IN: vp - vnode of file.
2403 * vap - va_mask identifies requested attributes.
2404 * If AT_XVATTR set, then optional attrs are requested
2405 * flags - ATTR_NOACLCHECK (CIFS server context)
2406 * cr - credentials of caller.
2407 * ct - caller context
2408 *
2409 * OUT: vap - attribute values.
2410 *
2411 * RETURN: 0 (always succeeds)
2412 */
2413 /* ARGSUSED */
2414 static int
2415 zfs_getattr(vnode_t *vp, vattr_t *vap, int flags, cred_t *cr,
2416 caller_context_t *ct)
2417 {
2418 znode_t *zp = VTOZ(vp);
2419 zfsvfs_t *zfsvfs = zp->z_zfsvfs;
2420 int error = 0;
2421 uint64_t links;
2422 uint64_t mtime[2], ctime[2];
2423 xvattr_t *xvap = (xvattr_t *)vap; /* vap may be an xvattr_t * */
2424 xoptattr_t *xoap = NULL;
2425 boolean_t skipaclchk = (flags & ATTR_NOACLCHECK) ? B_TRUE : B_FALSE;
2426 sa_bulk_attr_t bulk[2];
2427 int count = 0;
2428
2429 ZFS_ENTER(zfsvfs);
2430 ZFS_VERIFY_ZP(zp);
2431
2593 */
2594 vap->va_blksize = zfsvfs->z_max_blksz;
2595 }
2596
2597 ZFS_EXIT(zfsvfs);
2598 return (0);
2599 }
2600
2601 /*
2602 * Set the file attributes to the values contained in the
2603 * vattr structure.
2604 *
2605 * IN: vp - vnode of file to be modified.
2606 * vap - new attribute values.
2607 * If AT_XVATTR set, then optional attrs are being set
2608 * flags - ATTR_UTIME set if non-default time values provided.
2609 * - ATTR_NOACLCHECK (CIFS context only).
2610 * cr - credentials of caller.
2611 * ct - caller context
2612 *
2613 * RETURN: 0 if success
2614 * error code if failure
2615 *
2616 * Timestamps:
2617 * vp - ctime updated, mtime updated if size changed.
2618 */
2619 /* ARGSUSED */
2620 static int
2621 zfs_setattr(vnode_t *vp, vattr_t *vap, int flags, cred_t *cr,
2622 caller_context_t *ct)
2623 {
2624 znode_t *zp = VTOZ(vp);
2625 zfsvfs_t *zfsvfs = zp->z_zfsvfs;
2626 zilog_t *zilog;
2627 dmu_tx_t *tx;
2628 vattr_t oldva;
2629 xvattr_t tmpxvattr;
2630 uint_t mask = vap->va_mask;
2631 uint_t saved_mask = 0;
2632 int trim_mask = 0;
2633 uint64_t new_mode;
2634 uint64_t new_uid, new_gid;
3195 zfs_log_setattr(zilog, tx, TX_SETATTR, zp, vap, mask, fuidp);
3196
3197 mutex_exit(&zp->z_lock);
3198 if (mask & (AT_UID|AT_GID|AT_MODE))
3199 mutex_exit(&zp->z_acl_lock);
3200
3201 if (attrzp) {
3202 if (mask & (AT_UID|AT_GID|AT_MODE))
3203 mutex_exit(&attrzp->z_acl_lock);
3204 mutex_exit(&attrzp->z_lock);
3205 }
3206 out:
3207 if (err == 0 && attrzp) {
3208 err2 = sa_bulk_update(attrzp->z_sa_hdl, xattr_bulk,
3209 xattr_count, tx);
3210 ASSERT(err2 == 0);
3211 }
3212
3213 if (attrzp)
3214 VN_RELE(ZTOV(attrzp));
3215 if (aclp)
3216 zfs_acl_free(aclp);
3217
3218 if (fuidp) {
3219 zfs_fuid_info_free(fuidp);
3220 fuidp = NULL;
3221 }
3222
3223 if (err) {
3224 dmu_tx_abort(tx);
3225 if (err == ERESTART)
3226 goto top;
3227 } else {
3228 err2 = sa_bulk_update(zp->z_sa_hdl, bulk, count, tx);
3229 dmu_tx_commit(tx);
3230 }
3231
3232 out2:
3233 if (zfsvfs->z_os->os_sync == ZFS_SYNC_ALWAYS)
3234 zil_commit(zilog, 0);
3329 rwlp = &zp->z_parent_lock;
3330 rw = RW_READER;
3331
3332 } while (zp->z_id != sdzp->z_id);
3333
3334 return (0);
3335 }
3336
3337 /*
3338 * Move an entry from the provided source directory to the target
3339 * directory. Change the entry name as indicated.
3340 *
3341 * IN: sdvp - Source directory containing the "old entry".
3342 * snm - Old entry name.
3343 * tdvp - Target directory to contain the "new entry".
3344 * tnm - New entry name.
3345 * cr - credentials of caller.
3346 * ct - caller context
3347 * flags - case flags
3348 *
3349 * RETURN: 0 if success
3350 * error code if failure
3351 *
3352 * Timestamps:
3353 * sdvp,tdvp - ctime|mtime updated
3354 */
3355 /*ARGSUSED*/
3356 static int
3357 zfs_rename(vnode_t *sdvp, char *snm, vnode_t *tdvp, char *tnm, cred_t *cr,
3358 caller_context_t *ct, int flags)
3359 {
3360 znode_t *tdzp, *szp, *tzp;
3361 znode_t *sdzp = VTOZ(sdvp);
3362 zfsvfs_t *zfsvfs = sdzp->z_zfsvfs;
3363 zilog_t *zilog;
3364 vnode_t *realvp;
3365 zfs_dirlock_t *sdl, *tdl;
3366 dmu_tx_t *tx;
3367 zfs_zlock_t *zl;
3368 int cmp, serr, terr;
3369 int error = 0;
3370 int zflg = 0;
3677 rw_exit(&sdzp->z_name_lock);
3678
3679
3680 VN_RELE(ZTOV(szp));
3681 if (tzp)
3682 VN_RELE(ZTOV(tzp));
3683
3684 if (zfsvfs->z_os->os_sync == ZFS_SYNC_ALWAYS)
3685 zil_commit(zilog, 0);
3686
3687 ZFS_EXIT(zfsvfs);
3688 return (error);
3689 }
3690
3691 /*
3692 * Insert the indicated symbolic reference entry into the directory.
3693 *
3694 * IN: dvp - Directory to contain new symbolic link.
3695 * link - Name for new symlink entry.
3696 * vap - Attributes of new entry.
3697 * target - Target path of new symlink.
3698 * cr - credentials of caller.
3699 * ct - caller context
3700 * flags - case flags
3701 *
3702 * RETURN: 0 if success
3703 * error code if failure
3704 *
3705 * Timestamps:
3706 * dvp - ctime|mtime updated
3707 */
3708 /*ARGSUSED*/
3709 static int
3710 zfs_symlink(vnode_t *dvp, char *name, vattr_t *vap, char *link, cred_t *cr,
3711 caller_context_t *ct, int flags)
3712 {
3713 znode_t *zp, *dzp = VTOZ(dvp);
3714 zfs_dirlock_t *dl;
3715 dmu_tx_t *tx;
3716 zfsvfs_t *zfsvfs = dzp->z_zfsvfs;
3717 zilog_t *zilog;
3718 uint64_t len = strlen(link);
3719 int error;
3720 int zflg = ZNEW;
3721 zfs_acl_ids_t acl_ids;
3722 boolean_t fuid_dirtied;
3723 uint64_t txtype = TX_SYMLINK;
3829 zfs_acl_ids_free(&acl_ids);
3830
3831 dmu_tx_commit(tx);
3832
3833 zfs_dirent_unlock(dl);
3834
3835 VN_RELE(ZTOV(zp));
3836
3837 if (zfsvfs->z_os->os_sync == ZFS_SYNC_ALWAYS)
3838 zil_commit(zilog, 0);
3839
3840 ZFS_EXIT(zfsvfs);
3841 return (error);
3842 }
3843
3844 /*
3845 * Return, in the buffer contained in the provided uio structure,
3846 * the symbolic path referred to by vp.
3847 *
3848 * IN: vp - vnode of symbolic link.
3849 * uoip - structure to contain the link path.
3850 * cr - credentials of caller.
3851 * ct - caller context
3852 *
3853 * OUT: uio - structure to contain the link path.
3854 *
3855 * RETURN: 0 if success
3856 * error code if failure
3857 *
3858 * Timestamps:
3859 * vp - atime updated
3860 */
3861 /* ARGSUSED */
3862 static int
3863 zfs_readlink(vnode_t *vp, uio_t *uio, cred_t *cr, caller_context_t *ct)
3864 {
3865 znode_t *zp = VTOZ(vp);
3866 zfsvfs_t *zfsvfs = zp->z_zfsvfs;
3867 int error;
3868
3869 ZFS_ENTER(zfsvfs);
3870 ZFS_VERIFY_ZP(zp);
3871
3872 mutex_enter(&zp->z_lock);
3873 if (zp->z_is_sa)
3874 error = sa_lookup_uio(zp->z_sa_hdl,
3875 SA_ZPL_SYMLINK(zfsvfs), uio);
3876 else
3877 error = zfs_sa_readlink(zp, uio);
3878 mutex_exit(&zp->z_lock);
3879
3880 ZFS_ACCESSTIME_STAMP(zfsvfs, zp);
3881
3882 ZFS_EXIT(zfsvfs);
3883 return (error);
3884 }
3885
3886 /*
3887 * Insert a new entry into directory tdvp referencing svp.
3888 *
3889 * IN: tdvp - Directory to contain new entry.
3890 * svp - vnode of new entry.
3891 * name - name of new entry.
3892 * cr - credentials of caller.
3893 * ct - caller context
3894 *
3895 * RETURN: 0 if success
3896 * error code if failure
3897 *
3898 * Timestamps:
3899 * tdvp - ctime|mtime updated
3900 * svp - ctime updated
3901 */
3902 /* ARGSUSED */
3903 static int
3904 zfs_link(vnode_t *tdvp, vnode_t *svp, char *name, cred_t *cr,
3905 caller_context_t *ct, int flags)
3906 {
3907 znode_t *dzp = VTOZ(tdvp);
3908 znode_t *tzp, *szp;
3909 zfsvfs_t *zfsvfs = dzp->z_zfsvfs;
3910 zilog_t *zilog;
3911 zfs_dirlock_t *dl;
3912 dmu_tx_t *tx;
3913 vnode_t *realvp;
3914 int error;
3915 int zf = ZNEW;
3916 uint64_t parent;
4044 /* ARGSUSED */
4045 static int
4046 zfs_null_putapage(vnode_t *vp, page_t *pp, u_offset_t *offp,
4047 size_t *lenp, int flags, cred_t *cr)
4048 {
4049 pvn_write_done(pp, B_INVAL|B_FORCE|B_ERROR);
4050 return (0);
4051 }
4052
4053 /*
4054 * Push a page out to disk, klustering if possible.
4055 *
4056 * IN: vp - file to push page to.
4057 * pp - page to push.
4058 * flags - additional flags.
4059 * cr - credentials of caller.
4060 *
4061 * OUT: offp - start of range pushed.
4062 * lenp - len of range pushed.
4063 *
4064 * RETURN: 0 if success
4065 * error code if failure
4066 *
4067 * NOTE: callers must have locked the page to be pushed. On
4068 * exit, the page (and all other pages in the kluster) must be
4069 * unlocked.
4070 */
4071 /* ARGSUSED */
4072 static int
4073 zfs_putapage(vnode_t *vp, page_t *pp, u_offset_t *offp,
4074 size_t *lenp, int flags, cred_t *cr)
4075 {
4076 znode_t *zp = VTOZ(vp);
4077 zfsvfs_t *zfsvfs = zp->z_zfsvfs;
4078 dmu_tx_t *tx;
4079 u_offset_t off, koff;
4080 size_t len, klen;
4081 int err;
4082
4083 off = pp->p_offset;
4084 len = PAGESIZE;
4085 /*
4167 pvn_write_done(pp, (err ? B_ERROR : 0) | flags);
4168 if (offp)
4169 *offp = off;
4170 if (lenp)
4171 *lenp = len;
4172
4173 return (err);
4174 }
4175
4176 /*
4177 * Copy the portion of the file indicated from pages into the file.
4178 * The pages are stored in a page list attached to the files vnode.
4179 *
4180 * IN: vp - vnode of file to push page data to.
4181 * off - position in file to put data.
4182 * len - amount of data to write.
4183 * flags - flags to control the operation.
4184 * cr - credentials of caller.
4185 * ct - caller context.
4186 *
4187 * RETURN: 0 if success
4188 * error code if failure
4189 *
4190 * Timestamps:
4191 * vp - ctime|mtime updated
4192 */
4193 /*ARGSUSED*/
4194 static int
4195 zfs_putpage(vnode_t *vp, offset_t off, size_t len, int flags, cred_t *cr,
4196 caller_context_t *ct)
4197 {
4198 znode_t *zp = VTOZ(vp);
4199 zfsvfs_t *zfsvfs = zp->z_zfsvfs;
4200 page_t *pp;
4201 size_t io_len;
4202 u_offset_t io_off;
4203 uint_t blksz;
4204 rl_t *rl;
4205 int error = 0;
4206
4207 ZFS_ENTER(zfsvfs);
4208 ZFS_VERIFY_ZP(zp);
4333 (void) sa_update(zp->z_sa_hdl, SA_ZPL_ATIME(zfsvfs),
4334 (void *)&zp->z_atime, sizeof (zp->z_atime), tx);
4335 zp->z_atime_dirty = 0;
4336 mutex_exit(&zp->z_lock);
4337 dmu_tx_commit(tx);
4338 }
4339 }
4340
4341 zfs_zinactive(zp);
4342 rw_exit(&zfsvfs->z_teardown_inactive_lock);
4343 }
4344
4345 /*
4346 * Bounds-check the seek operation.
4347 *
4348 * IN: vp - vnode seeking within
4349 * ooff - old file offset
4350 * noffp - pointer to new file offset
4351 * ct - caller context
4352 *
4353 * RETURN: 0 if success
4354 * EINVAL if new offset invalid
4355 */
4356 /* ARGSUSED */
4357 static int
4358 zfs_seek(vnode_t *vp, offset_t ooff, offset_t *noffp,
4359 caller_context_t *ct)
4360 {
4361 if (vp->v_type == VDIR)
4362 return (0);
4363 return ((*noffp < 0 || *noffp > MAXOFFSET_T) ? EINVAL : 0);
4364 }
4365
4366 /*
4367 * Pre-filter the generic locking function to trap attempts to place
4368 * a mandatory lock on a memory mapped file.
4369 */
4370 static int
4371 zfs_frlock(vnode_t *vp, int cmd, flock64_t *bfp, int flag, offset_t offset,
4372 flk_callback_t *flk_cbp, cred_t *cr, caller_context_t *ct)
4373 {
4374 znode_t *zp = VTOZ(vp);
4470 * Return pointers to the pages for the file region [off, off + len]
4471 * in the pl array. If plsz is greater than len, this function may
4472 * also return page pointers from after the specified region
4473 * (i.e. the region [off, off + plsz]). These additional pages are
4474 * only returned if they are already in the cache, or were created as
4475 * part of a klustered read.
4476 *
4477 * IN: vp - vnode of file to get data from.
4478 * off - position in file to get data from.
4479 * len - amount of data to retrieve.
4480 * plsz - length of provided page list.
4481 * seg - segment to obtain pages for.
4482 * addr - virtual address of fault.
4483 * rw - mode of created pages.
4484 * cr - credentials of caller.
4485 * ct - caller context.
4486 *
4487 * OUT: protp - protection mode of created pages.
4488 * pl - list of pages created.
4489 *
4490 * RETURN: 0 if success
4491 * error code if failure
4492 *
4493 * Timestamps:
4494 * vp - atime updated
4495 */
4496 /* ARGSUSED */
4497 static int
4498 zfs_getpage(vnode_t *vp, offset_t off, size_t len, uint_t *protp,
4499 page_t *pl[], size_t plsz, struct seg *seg, caddr_t addr,
4500 enum seg_rw rw, cred_t *cr, caller_context_t *ct)
4501 {
4502 znode_t *zp = VTOZ(vp);
4503 zfsvfs_t *zfsvfs = zp->z_zfsvfs;
4504 page_t **pl0 = pl;
4505 int err = 0;
4506
4507 /* we do our own caching, faultahead is unnecessary */
4508 if (pl == NULL)
4509 return (0);
4510 else if (len > plsz)
4511 len = plsz;
4555 if (err) {
4556 /*
4557 * Release any pages we have previously locked.
4558 */
4559 while (pl > pl0)
4560 page_unlock(*--pl);
4561 } else {
4562 ZFS_ACCESSTIME_STAMP(zfsvfs, zp);
4563 }
4564
4565 *pl = NULL;
4566
4567 ZFS_EXIT(zfsvfs);
4568 return (err);
4569 }
4570
4571 /*
4572 * Request a memory map for a section of a file. This code interacts
4573 * with common code and the VM system as follows:
4574 *
4575 * common code calls mmap(), which ends up in smmap_common()
4576 *
4577 * this calls VOP_MAP(), which takes you into (say) zfs
4578 *
4579 * zfs_map() calls as_map(), passing segvn_create() as the callback
4580 *
4581 * segvn_create() creates the new segment and calls VOP_ADDMAP()
4582 *
4583 * zfs_addmap() updates z_mapcnt
4584 */
4585 /*ARGSUSED*/
4586 static int
4587 zfs_map(vnode_t *vp, offset_t off, struct as *as, caddr_t *addrp,
4588 size_t len, uchar_t prot, uchar_t maxprot, uint_t flags, cred_t *cr,
4589 caller_context_t *ct)
4590 {
4591 znode_t *zp = VTOZ(vp);
4592 zfsvfs_t *zfsvfs = zp->z_zfsvfs;
4593 segvn_crargs_t vn_a;
4594 int error;
4595
4596 ZFS_ENTER(zfsvfs);
4597 ZFS_VERIFY_ZP(zp);
4598
4599 if ((prot & PROT_WRITE) && (zp->z_pflags &
4600 (ZFS_IMMUTABLE | ZFS_READONLY | ZFS_APPENDONLY))) {
4601 ZFS_EXIT(zfsvfs);
4602 return (SET_ERROR(EPERM));
4603 }
4705 vn_has_cached_data(vp))
4706 (void) VOP_PUTPAGE(vp, off, len, B_ASYNC, cr, ct);
4707
4708 return (0);
4709 }
4710
4711 /*
4712 * Free or allocate space in a file. Currently, this function only
4713 * supports the `F_FREESP' command. However, this command is somewhat
4714 * misnamed, as its functionality includes the ability to allocate as
4715 * well as free space.
4716 *
4717 * IN: vp - vnode of file to free data in.
4718 * cmd - action to take (only F_FREESP supported).
4719 * bfp - section of file to free/alloc.
4720 * flag - current file open mode flags.
4721 * offset - current file offset.
4722 * cr - credentials of caller [UNUSED].
4723 * ct - caller context.
4724 *
4725 * RETURN: 0 if success
4726 * error code if failure
4727 *
4728 * Timestamps:
4729 * vp - ctime|mtime updated
4730 */
4731 /* ARGSUSED */
4732 static int
4733 zfs_space(vnode_t *vp, int cmd, flock64_t *bfp, int flag,
4734 offset_t offset, cred_t *cr, caller_context_t *ct)
4735 {
4736 znode_t *zp = VTOZ(vp);
4737 zfsvfs_t *zfsvfs = zp->z_zfsvfs;
4738 uint64_t off, len;
4739 int error;
4740
4741 ZFS_ENTER(zfsvfs);
4742 ZFS_VERIFY_ZP(zp);
4743
4744 if (cmd != F_FREESP) {
4745 ZFS_EXIT(zfsvfs);
4746 return (SET_ERROR(EINVAL));
4921 {
4922 znode_t *zp = VTOZ(vp);
4923 zfsvfs_t *zfsvfs = zp->z_zfsvfs;
4924 int error;
4925 boolean_t skipaclchk = (flag & ATTR_NOACLCHECK) ? B_TRUE : B_FALSE;
4926 zilog_t *zilog = zfsvfs->z_log;
4927
4928 ZFS_ENTER(zfsvfs);
4929 ZFS_VERIFY_ZP(zp);
4930
4931 error = zfs_setacl(zp, vsecp, skipaclchk, cr);
4932
4933 if (zfsvfs->z_os->os_sync == ZFS_SYNC_ALWAYS)
4934 zil_commit(zilog, 0);
4935
4936 ZFS_EXIT(zfsvfs);
4937 return (error);
4938 }
4939
4940 /*
4941 * Tunable, both must be a power of 2.
4942 *
4943 * zcr_blksz_min: the smallest read we may consider to loan out an arcbuf
4944 * zcr_blksz_max: if set to less than the file block size, allow loaning out of
4945 * an arcbuf for a partial block read
4946 */
4947 int zcr_blksz_min = (1 << 10); /* 1K */
4948 int zcr_blksz_max = (1 << 17); /* 128K */
4949
4950 /*ARGSUSED*/
4951 static int
4952 zfs_reqzcbuf(vnode_t *vp, enum uio_rw ioflag, xuio_t *xuio, cred_t *cr,
4953 caller_context_t *ct)
4954 {
4955 znode_t *zp = VTOZ(vp);
4956 zfsvfs_t *zfsvfs = zp->z_zfsvfs;
4957 int max_blksz = zfsvfs->z_max_blksz;
4958 uio_t *uio = &xuio->xu_uio;
4959 ssize_t size = uio->uio_resid;
4960 offset_t offset = uio->uio_loffset;
4961 int blksz;
4962 int fullblk, i;
4963 arc_buf_t *abuf;
4964 ssize_t maxsize;
4965 int preamble, postamble;
4966
4967 if (xuio->xu_type != UIOTYPE_ZEROCOPY)
5201 };
5202
5203 /*
5204 * special share hidden files vnode operations template
5205 */
5206 vnodeops_t *zfs_sharevnodeops;
5207 const fs_operation_def_t zfs_sharevnodeops_template[] = {
5208 VOPNAME_GETATTR, { .vop_getattr = zfs_getattr },
5209 VOPNAME_ACCESS, { .vop_access = zfs_access },
5210 VOPNAME_INACTIVE, { .vop_inactive = zfs_inactive },
5211 VOPNAME_FID, { .vop_fid = zfs_fid },
5212 VOPNAME_PATHCONF, { .vop_pathconf = zfs_pathconf },
5213 VOPNAME_GETSECATTR, { .vop_getsecattr = zfs_getsecattr },
5214 VOPNAME_SETSECATTR, { .vop_setsecattr = zfs_setsecattr },
5215 VOPNAME_VNEVENT, { .vop_vnevent = fs_vnevent_support },
5216 NULL, NULL
5217 };
5218
5219 /*
5220 * Extended attribute directory vnode operations template
5221 * This template is identical to the directory vnodes
5222 * operation template except for restricted operations:
5223 * VOP_MKDIR()
5224 * VOP_SYMLINK()
5225 * Note that there are other restrictions embedded in:
5226 * zfs_create() - restrict type to VREG
5227 * zfs_link() - no links into/out of attribute space
5228 * zfs_rename() - no moves into/out of attribute space
5229 */
5230 vnodeops_t *zfs_xdvnodeops;
5231 const fs_operation_def_t zfs_xdvnodeops_template[] = {
5232 VOPNAME_OPEN, { .vop_open = zfs_open },
5233 VOPNAME_CLOSE, { .vop_close = zfs_close },
5234 VOPNAME_IOCTL, { .vop_ioctl = zfs_ioctl },
5235 VOPNAME_GETATTR, { .vop_getattr = zfs_getattr },
5236 VOPNAME_SETATTR, { .vop_setattr = zfs_setattr },
5237 VOPNAME_ACCESS, { .vop_access = zfs_access },
5238 VOPNAME_LOOKUP, { .vop_lookup = zfs_lookup },
5239 VOPNAME_CREATE, { .vop_create = zfs_create },
5240 VOPNAME_REMOVE, { .vop_remove = zfs_remove },
5241 VOPNAME_LINK, { .vop_link = zfs_link },
5242 VOPNAME_RENAME, { .vop_rename = zfs_rename },
5243 VOPNAME_MKDIR, { .error = zfs_inval },
5244 VOPNAME_RMDIR, { .vop_rmdir = zfs_rmdir },
|
416 if (error)
417 break;
418 }
419 return (error);
420 }
421
422 offset_t zfs_read_chunk_size = 1024 * 1024; /* Tunable */
423
424 /*
425 * Read bytes from specified file into supplied buffer.
426 *
427 * IN: vp - vnode of file to be read from.
428 * uio - structure supplying read location, range info,
429 * and return buffer.
430 * ioflag - SYNC flags; used to provide FRSYNC semantics.
431 * cr - credentials of caller.
432 * ct - caller context
433 *
434 * OUT: uio - updated offset and range, buffer filled.
435 *
436 * RETURN: 0 on success, error code on failure.
437 *
438 * Side Effects:
439 * vp - atime updated if byte count > 0
440 */
441 /* ARGSUSED */
442 static int
443 zfs_read(vnode_t *vp, uio_t *uio, int ioflag, cred_t *cr, caller_context_t *ct)
444 {
445 znode_t *zp = VTOZ(vp);
446 zfsvfs_t *zfsvfs = zp->z_zfsvfs;
447 objset_t *os;
448 ssize_t n, nbytes;
449 int error = 0;
450 rl_t *rl;
451 xuio_t *xuio = NULL;
452
453 ZFS_ENTER(zfsvfs);
454 ZFS_VERIFY_ZP(zp);
455 os = zfsvfs->z_os;
456
552 error = SET_ERROR(EIO);
553 break;
554 }
555
556 n -= nbytes;
557 }
558 out:
559 zfs_range_unlock(rl);
560
561 ZFS_ACCESSTIME_STAMP(zfsvfs, zp);
562 ZFS_EXIT(zfsvfs);
563 return (error);
564 }
565
566 /*
567 * Write the bytes to a file.
568 *
569 * IN: vp - vnode of file to be written to.
570 * uio - structure supplying write location, range info,
571 * and data buffer.
572 * ioflag - FAPPEND, FSYNC, and/or FDSYNC. FAPPEND is
573 * set if in append mode.
574 * cr - credentials of caller.
575 * ct - caller context (NFS/CIFS fem monitor only)
576 *
577 * OUT: uio - updated offset and range.
578 *
579 * RETURN: 0 on success, error code on failure.
580 *
581 * Timestamps:
582 * vp - ctime|mtime updated if byte count > 0
583 */
584
585 /* ARGSUSED */
586 static int
587 zfs_write(vnode_t *vp, uio_t *uio, int ioflag, cred_t *cr, caller_context_t *ct)
588 {
589 znode_t *zp = VTOZ(vp);
590 rlim64_t limit = uio->uio_llimit;
591 ssize_t start_resid = uio->uio_resid;
592 ssize_t tx_bytes;
593 uint64_t end_size;
594 dmu_tx_t *tx;
595 zfsvfs_t *zfsvfs = zp->z_zfsvfs;
596 zilog_t *zilog;
597 offset_t woff;
598 ssize_t n, nbytes;
599 rl_t *rl;
1130 return (error);
1131 }
1132
1133
1134 /*
1135 * Lookup an entry in a directory, or an extended attribute directory.
1136 * If it exists, return a held vnode reference for it.
1137 *
1138 * IN: dvp - vnode of directory to search.
1139 * nm - name of entry to lookup.
1140 * pnp - full pathname to lookup [UNUSED].
1141 * flags - LOOKUP_XATTR set if looking for an attribute.
1142 * rdir - root directory vnode [UNUSED].
1143 * cr - credentials of caller.
1144 * ct - caller context
1145 * direntflags - directory lookup flags
1146 * realpnp - returned pathname.
1147 *
1148 * OUT: vpp - vnode of located entry, NULL if not found.
1149 *
1150 * RETURN: 0 on success, error code on failure.
1151 *
1152 * Timestamps:
1153 * NA
1154 */
1155 /* ARGSUSED */
1156 static int
1157 zfs_lookup(vnode_t *dvp, char *nm, vnode_t **vpp, struct pathname *pnp,
1158 int flags, vnode_t *rdir, cred_t *cr, caller_context_t *ct,
1159 int *direntflags, pathname_t *realpnp)
1160 {
1161 znode_t *zdp = VTOZ(dvp);
1162 zfsvfs_t *zfsvfs = zdp->z_zfsvfs;
1163 int error = 0;
1164
1165 /* fast path */
1166 if (!(flags & (LOOKUP_XATTR | FIGNORECASE))) {
1167
1168 if (dvp->v_type != VDIR) {
1169 return (SET_ERROR(ENOTDIR));
1170 } else if (zdp->z_sa_hdl == NULL) {
1271 return (error);
1272 }
1273
1274 /*
1275 * Attempt to create a new entry in a directory. If the entry
1276 * already exists, truncate the file if permissible, else return
1277 * an error. Return the vp of the created or trunc'd file.
1278 *
1279 * IN: dvp - vnode of directory to put new file entry in.
1280 * name - name of new file entry.
1281 * vap - attributes of new file.
1282 * excl - flag indicating exclusive or non-exclusive mode.
1283 * mode - mode to open file with.
1284 * cr - credentials of caller.
1285 * flag - large file flag [UNUSED].
1286 * ct - caller context
1287 * vsecp - ACL to be set
1288 *
1289 * OUT: vpp - vnode of created or trunc'd entry.
1290 *
1291 * RETURN: 0 on success, error code on failure.
1292 *
1293 * Timestamps:
1294 * dvp - ctime|mtime updated if new entry created
1295 * vp - ctime|mtime always, atime if new
1296 */
1297
1298 /* ARGSUSED */
1299 static int
1300 zfs_create(vnode_t *dvp, char *name, vattr_t *vap, vcexcl_t excl,
1301 int mode, vnode_t **vpp, cred_t *cr, int flag, caller_context_t *ct,
1302 vsecattr_t *vsecp)
1303 {
1304 znode_t *zp, *dzp = VTOZ(dvp);
1305 zfsvfs_t *zfsvfs = dzp->z_zfsvfs;
1306 zilog_t *zilog;
1307 objset_t *os;
1308 zfs_dirlock_t *dl;
1309 dmu_tx_t *tx;
1310 int error;
1311 ksid_t *ksid;
1521 *vpp = ZTOV(zp);
1522 error = specvp_check(vpp, cr);
1523 }
1524
1525 if (zfsvfs->z_os->os_sync == ZFS_SYNC_ALWAYS)
1526 zil_commit(zilog, 0);
1527
1528 ZFS_EXIT(zfsvfs);
1529 return (error);
1530 }
1531
1532 /*
1533 * Remove an entry from a directory.
1534 *
1535 * IN: dvp - vnode of directory to remove entry from.
1536 * name - name of entry to remove.
1537 * cr - credentials of caller.
1538 * ct - caller context
1539 * flags - case flags
1540 *
1541 * RETURN: 0 on success, error code on failure.
1542 *
1543 * Timestamps:
1544 * dvp - ctime|mtime
1545 * vp - ctime (if nlink > 0)
1546 */
1547
1548 uint64_t null_xattr = 0;
1549
1550 /*ARGSUSED*/
1551 static int
1552 zfs_remove(vnode_t *dvp, char *name, cred_t *cr, caller_context_t *ct,
1553 int flags)
1554 {
1555 znode_t *zp, *dzp = VTOZ(dvp);
1556 znode_t *xzp;
1557 vnode_t *vp;
1558 zfsvfs_t *zfsvfs = dzp->z_zfsvfs;
1559 zilog_t *zilog;
1560 uint64_t acl_obj, xattr_obj;
1561 uint64_t xattr_obj_unlinked = 0;
1751 VN_RELE(vp);
1752 if (xzp)
1753 VN_RELE(ZTOV(xzp));
1754
1755 if (zfsvfs->z_os->os_sync == ZFS_SYNC_ALWAYS)
1756 zil_commit(zilog, 0);
1757
1758 ZFS_EXIT(zfsvfs);
1759 return (error);
1760 }
1761
1762 /*
1763 * Create a new directory and insert it into dvp using the name
1764 * provided. Return a pointer to the inserted directory.
1765 *
1766 * IN: dvp - vnode of directory to add subdir to.
1767 * dirname - name of new directory.
1768 * vap - attributes of new directory.
1769 * cr - credentials of caller.
1770 * ct - caller context
1771 * flags - case flags
1772 * vsecp - ACL to be set
1773 *
1774 * OUT: vpp - vnode of created directory.
1775 *
1776 * RETURN: 0 on success, error code on failure.
1777 *
1778 * Timestamps:
1779 * dvp - ctime|mtime updated
1780 * vp - ctime|mtime|atime updated
1781 */
1782 /*ARGSUSED*/
1783 static int
1784 zfs_mkdir(vnode_t *dvp, char *dirname, vattr_t *vap, vnode_t **vpp, cred_t *cr,
1785 caller_context_t *ct, int flags, vsecattr_t *vsecp)
1786 {
1787 znode_t *zp, *dzp = VTOZ(dvp);
1788 zfsvfs_t *zfsvfs = dzp->z_zfsvfs;
1789 zilog_t *zilog;
1790 zfs_dirlock_t *dl;
1791 uint64_t txtype;
1792 dmu_tx_t *tx;
1793 int error;
1794 int zf = ZNEW;
1795 ksid_t *ksid;
1796 uid_t uid;
1936
1937 if (zfsvfs->z_os->os_sync == ZFS_SYNC_ALWAYS)
1938 zil_commit(zilog, 0);
1939
1940 ZFS_EXIT(zfsvfs);
1941 return (0);
1942 }
1943
1944 /*
1945 * Remove a directory subdir entry. If the current working
1946 * directory is the same as the subdir to be removed, the
1947 * remove will fail.
1948 *
1949 * IN: dvp - vnode of directory to remove from.
1950 * name - name of directory to be removed.
1951 * cwd - vnode of current working directory.
1952 * cr - credentials of caller.
1953 * ct - caller context
1954 * flags - case flags
1955 *
1956 * RETURN: 0 on success, error code on failure.
1957 *
1958 * Timestamps:
1959 * dvp - ctime|mtime updated
1960 */
1961 /*ARGSUSED*/
1962 static int
1963 zfs_rmdir(vnode_t *dvp, char *name, vnode_t *cwd, cred_t *cr,
1964 caller_context_t *ct, int flags)
1965 {
1966 znode_t *dzp = VTOZ(dvp);
1967 znode_t *zp;
1968 vnode_t *vp;
1969 zfsvfs_t *zfsvfs = dzp->z_zfsvfs;
1970 zilog_t *zilog;
1971 zfs_dirlock_t *dl;
1972 dmu_tx_t *tx;
1973 int error;
1974 int zflg = ZEXISTS;
1975
1976 ZFS_ENTER(zfsvfs);
2054
2055 dmu_tx_commit(tx);
2056
2057 rw_exit(&zp->z_parent_lock);
2058 rw_exit(&zp->z_name_lock);
2059 out:
2060 zfs_dirent_unlock(dl);
2061
2062 VN_RELE(vp);
2063
2064 if (zfsvfs->z_os->os_sync == ZFS_SYNC_ALWAYS)
2065 zil_commit(zilog, 0);
2066
2067 ZFS_EXIT(zfsvfs);
2068 return (error);
2069 }
2070
2071 /*
2072 * Read as many directory entries as will fit into the provided
2073 * buffer from the given directory cursor position (specified in
2074 * the uio structure).
2075 *
2076 * IN: vp - vnode of directory to read.
2077 * uio - structure supplying read location, range info,
2078 * and return buffer.
2079 * cr - credentials of caller.
2080 * ct - caller context
2081 * flags - case flags
2082 *
2083 * OUT: uio - updated offset and range, buffer filled.
2084 * eofp - set to true if end-of-file detected.
2085 *
2086 * RETURN: 0 on success, error code on failure.
2087 *
2088 * Timestamps:
2089 * vp - atime updated
2090 *
2091 * Note that the low 4 bits of the cookie returned by zap is always zero.
2092 * This allows us to use the low range for "special" directory entries:
2093 * We use 0 for '.', and 1 for '..'. If this is the root of the filesystem,
2094 * we use the offset 2 for the '.zfs' directory.
2095 */
2096 /* ARGSUSED */
2097 static int
2098 zfs_readdir(vnode_t *vp, uio_t *uio, cred_t *cr, int *eofp,
2099 caller_context_t *ct, int flags)
2100 {
2101 znode_t *zp = VTOZ(vp);
2102 iovec_t *iovp;
2103 edirent_t *eodp;
2104 dirent64_t *odp;
2105 zfsvfs_t *zfsvfs = zp->z_zfsvfs;
2106 objset_t *os;
2385 zil_commit(zfsvfs->z_log, zp->z_id);
2386 ZFS_EXIT(zfsvfs);
2387 }
2388 return (0);
2389 }
2390
2391
2392 /*
2393 * Get the requested file attributes and place them in the provided
2394 * vattr structure.
2395 *
2396 * IN: vp - vnode of file.
2397 * vap - va_mask identifies requested attributes.
2398 * If AT_XVATTR set, then optional attrs are requested
2399 * flags - ATTR_NOACLCHECK (CIFS server context)
2400 * cr - credentials of caller.
2401 * ct - caller context
2402 *
2403 * OUT: vap - attribute values.
2404 *
2405 * RETURN: 0 (always succeeds).
2406 */
2407 /* ARGSUSED */
2408 static int
2409 zfs_getattr(vnode_t *vp, vattr_t *vap, int flags, cred_t *cr,
2410 caller_context_t *ct)
2411 {
2412 znode_t *zp = VTOZ(vp);
2413 zfsvfs_t *zfsvfs = zp->z_zfsvfs;
2414 int error = 0;
2415 uint64_t links;
2416 uint64_t mtime[2], ctime[2];
2417 xvattr_t *xvap = (xvattr_t *)vap; /* vap may be an xvattr_t * */
2418 xoptattr_t *xoap = NULL;
2419 boolean_t skipaclchk = (flags & ATTR_NOACLCHECK) ? B_TRUE : B_FALSE;
2420 sa_bulk_attr_t bulk[2];
2421 int count = 0;
2422
2423 ZFS_ENTER(zfsvfs);
2424 ZFS_VERIFY_ZP(zp);
2425
2587 */
2588 vap->va_blksize = zfsvfs->z_max_blksz;
2589 }
2590
2591 ZFS_EXIT(zfsvfs);
2592 return (0);
2593 }
2594
2595 /*
2596 * Set the file attributes to the values contained in the
2597 * vattr structure.
2598 *
2599 * IN: vp - vnode of file to be modified.
2600 * vap - new attribute values.
2601 * If AT_XVATTR set, then optional attrs are being set
2602 * flags - ATTR_UTIME set if non-default time values provided.
2603 * - ATTR_NOACLCHECK (CIFS context only).
2604 * cr - credentials of caller.
2605 * ct - caller context
2606 *
2607 * RETURN: 0 on success, error code on failure.
2608 *
2609 * Timestamps:
2610 * vp - ctime updated, mtime updated if size changed.
2611 */
2612 /* ARGSUSED */
2613 static int
2614 zfs_setattr(vnode_t *vp, vattr_t *vap, int flags, cred_t *cr,
2615 caller_context_t *ct)
2616 {
2617 znode_t *zp = VTOZ(vp);
2618 zfsvfs_t *zfsvfs = zp->z_zfsvfs;
2619 zilog_t *zilog;
2620 dmu_tx_t *tx;
2621 vattr_t oldva;
2622 xvattr_t tmpxvattr;
2623 uint_t mask = vap->va_mask;
2624 uint_t saved_mask = 0;
2625 int trim_mask = 0;
2626 uint64_t new_mode;
2627 uint64_t new_uid, new_gid;
3188 zfs_log_setattr(zilog, tx, TX_SETATTR, zp, vap, mask, fuidp);
3189
3190 mutex_exit(&zp->z_lock);
3191 if (mask & (AT_UID|AT_GID|AT_MODE))
3192 mutex_exit(&zp->z_acl_lock);
3193
3194 if (attrzp) {
3195 if (mask & (AT_UID|AT_GID|AT_MODE))
3196 mutex_exit(&attrzp->z_acl_lock);
3197 mutex_exit(&attrzp->z_lock);
3198 }
3199 out:
3200 if (err == 0 && attrzp) {
3201 err2 = sa_bulk_update(attrzp->z_sa_hdl, xattr_bulk,
3202 xattr_count, tx);
3203 ASSERT(err2 == 0);
3204 }
3205
3206 if (attrzp)
3207 VN_RELE(ZTOV(attrzp));
3208
3209 if (aclp)
3210 zfs_acl_free(aclp);
3211
3212 if (fuidp) {
3213 zfs_fuid_info_free(fuidp);
3214 fuidp = NULL;
3215 }
3216
3217 if (err) {
3218 dmu_tx_abort(tx);
3219 if (err == ERESTART)
3220 goto top;
3221 } else {
3222 err2 = sa_bulk_update(zp->z_sa_hdl, bulk, count, tx);
3223 dmu_tx_commit(tx);
3224 }
3225
3226 out2:
3227 if (zfsvfs->z_os->os_sync == ZFS_SYNC_ALWAYS)
3228 zil_commit(zilog, 0);
3323 rwlp = &zp->z_parent_lock;
3324 rw = RW_READER;
3325
3326 } while (zp->z_id != sdzp->z_id);
3327
3328 return (0);
3329 }
3330
3331 /*
3332 * Move an entry from the provided source directory to the target
3333 * directory. Change the entry name as indicated.
3334 *
3335 * IN: sdvp - Source directory containing the "old entry".
3336 * snm - Old entry name.
3337 * tdvp - Target directory to contain the "new entry".
3338 * tnm - New entry name.
3339 * cr - credentials of caller.
3340 * ct - caller context
3341 * flags - case flags
3342 *
3343 * RETURN: 0 on success, error code on failure.
3344 *
3345 * Timestamps:
3346 * sdvp,tdvp - ctime|mtime updated
3347 */
3348 /*ARGSUSED*/
3349 static int
3350 zfs_rename(vnode_t *sdvp, char *snm, vnode_t *tdvp, char *tnm, cred_t *cr,
3351 caller_context_t *ct, int flags)
3352 {
3353 znode_t *tdzp, *szp, *tzp;
3354 znode_t *sdzp = VTOZ(sdvp);
3355 zfsvfs_t *zfsvfs = sdzp->z_zfsvfs;
3356 zilog_t *zilog;
3357 vnode_t *realvp;
3358 zfs_dirlock_t *sdl, *tdl;
3359 dmu_tx_t *tx;
3360 zfs_zlock_t *zl;
3361 int cmp, serr, terr;
3362 int error = 0;
3363 int zflg = 0;
3670 rw_exit(&sdzp->z_name_lock);
3671
3672
3673 VN_RELE(ZTOV(szp));
3674 if (tzp)
3675 VN_RELE(ZTOV(tzp));
3676
3677 if (zfsvfs->z_os->os_sync == ZFS_SYNC_ALWAYS)
3678 zil_commit(zilog, 0);
3679
3680 ZFS_EXIT(zfsvfs);
3681 return (error);
3682 }
3683
3684 /*
3685 * Insert the indicated symbolic reference entry into the directory.
3686 *
3687 * IN: dvp - Directory to contain new symbolic link.
3688 * link - Name for new symlink entry.
3689 * vap - Attributes of new entry.
3690 * cr - credentials of caller.
3691 * ct - caller context
3692 * flags - case flags
3693 *
3694 * RETURN: 0 on success, error code on failure.
3695 *
3696 * Timestamps:
3697 * dvp - ctime|mtime updated
3698 */
3699 /*ARGSUSED*/
3700 static int
3701 zfs_symlink(vnode_t *dvp, char *name, vattr_t *vap, char *link, cred_t *cr,
3702 caller_context_t *ct, int flags)
3703 {
3704 znode_t *zp, *dzp = VTOZ(dvp);
3705 zfs_dirlock_t *dl;
3706 dmu_tx_t *tx;
3707 zfsvfs_t *zfsvfs = dzp->z_zfsvfs;
3708 zilog_t *zilog;
3709 uint64_t len = strlen(link);
3710 int error;
3711 int zflg = ZNEW;
3712 zfs_acl_ids_t acl_ids;
3713 boolean_t fuid_dirtied;
3714 uint64_t txtype = TX_SYMLINK;
3820 zfs_acl_ids_free(&acl_ids);
3821
3822 dmu_tx_commit(tx);
3823
3824 zfs_dirent_unlock(dl);
3825
3826 VN_RELE(ZTOV(zp));
3827
3828 if (zfsvfs->z_os->os_sync == ZFS_SYNC_ALWAYS)
3829 zil_commit(zilog, 0);
3830
3831 ZFS_EXIT(zfsvfs);
3832 return (error);
3833 }
3834
3835 /*
3836 * Return, in the buffer contained in the provided uio structure,
3837 * the symbolic path referred to by vp.
3838 *
3839 * IN: vp - vnode of symbolic link.
3840 * uio - structure to contain the link path.
3841 * cr - credentials of caller.
3842 * ct - caller context
3843 *
3844 * OUT: uio - structure containing the link path.
3845 *
3846 * RETURN: 0 on success, error code on failure.
3847 *
3848 * Timestamps:
3849 * vp - atime updated
3850 */
3851 /* ARGSUSED */
3852 static int
3853 zfs_readlink(vnode_t *vp, uio_t *uio, cred_t *cr, caller_context_t *ct)
3854 {
3855 znode_t *zp = VTOZ(vp);
3856 zfsvfs_t *zfsvfs = zp->z_zfsvfs;
3857 int error;
3858
3859 ZFS_ENTER(zfsvfs);
3860 ZFS_VERIFY_ZP(zp);
3861
3862 mutex_enter(&zp->z_lock);
3863 if (zp->z_is_sa)
3864 error = sa_lookup_uio(zp->z_sa_hdl,
3865 SA_ZPL_SYMLINK(zfsvfs), uio);
3866 else
3867 error = zfs_sa_readlink(zp, uio);
3868 mutex_exit(&zp->z_lock);
3869
3870 ZFS_ACCESSTIME_STAMP(zfsvfs, zp);
3871
3872 ZFS_EXIT(zfsvfs);
3873 return (error);
3874 }
3875
3876 /*
3877 * Insert a new entry into directory tdvp referencing svp.
3878 *
3879 * IN: tdvp - Directory to contain new entry.
3880 * svp - vnode of new entry.
3881 * name - name of new entry.
3882 * cr - credentials of caller.
3883 * ct - caller context
3884 *
3885 * RETURN: 0 on success, error code on failure.
3886 *
3887 * Timestamps:
3888 * tdvp - ctime|mtime updated
3889 * svp - ctime updated
3890 */
3891 /* ARGSUSED */
3892 static int
3893 zfs_link(vnode_t *tdvp, vnode_t *svp, char *name, cred_t *cr,
3894 caller_context_t *ct, int flags)
3895 {
3896 znode_t *dzp = VTOZ(tdvp);
3897 znode_t *tzp, *szp;
3898 zfsvfs_t *zfsvfs = dzp->z_zfsvfs;
3899 zilog_t *zilog;
3900 zfs_dirlock_t *dl;
3901 dmu_tx_t *tx;
3902 vnode_t *realvp;
3903 int error;
3904 int zf = ZNEW;
3905 uint64_t parent;
4033 /* ARGSUSED */
4034 static int
4035 zfs_null_putapage(vnode_t *vp, page_t *pp, u_offset_t *offp,
4036 size_t *lenp, int flags, cred_t *cr)
4037 {
4038 pvn_write_done(pp, B_INVAL|B_FORCE|B_ERROR);
4039 return (0);
4040 }
4041
4042 /*
4043 * Push a page out to disk, klustering if possible.
4044 *
4045 * IN: vp - file to push page to.
4046 * pp - page to push.
4047 * flags - additional flags.
4048 * cr - credentials of caller.
4049 *
4050 * OUT: offp - start of range pushed.
4051 * lenp - len of range pushed.
4052 *
4053 * RETURN: 0 on success, error code on failure.
4054 *
4055 * NOTE: callers must have locked the page to be pushed. On
4056 * exit, the page (and all other pages in the kluster) must be
4057 * unlocked.
4058 */
4059 /* ARGSUSED */
4060 static int
4061 zfs_putapage(vnode_t *vp, page_t *pp, u_offset_t *offp,
4062 size_t *lenp, int flags, cred_t *cr)
4063 {
4064 znode_t *zp = VTOZ(vp);
4065 zfsvfs_t *zfsvfs = zp->z_zfsvfs;
4066 dmu_tx_t *tx;
4067 u_offset_t off, koff;
4068 size_t len, klen;
4069 int err;
4070
4071 off = pp->p_offset;
4072 len = PAGESIZE;
4073 /*
4155 pvn_write_done(pp, (err ? B_ERROR : 0) | flags);
4156 if (offp)
4157 *offp = off;
4158 if (lenp)
4159 *lenp = len;
4160
4161 return (err);
4162 }
4163
4164 /*
4165 * Copy the portion of the file indicated from pages into the file.
4166 * The pages are stored in a page list attached to the files vnode.
4167 *
4168 * IN: vp - vnode of file to push page data to.
4169 * off - position in file to put data.
4170 * len - amount of data to write.
4171 * flags - flags to control the operation.
4172 * cr - credentials of caller.
4173 * ct - caller context.
4174 *
4175 * RETURN: 0 on success, error code on failure.
4176 *
4177 * Timestamps:
4178 * vp - ctime|mtime updated
4179 */
4180 /*ARGSUSED*/
4181 static int
4182 zfs_putpage(vnode_t *vp, offset_t off, size_t len, int flags, cred_t *cr,
4183 caller_context_t *ct)
4184 {
4185 znode_t *zp = VTOZ(vp);
4186 zfsvfs_t *zfsvfs = zp->z_zfsvfs;
4187 page_t *pp;
4188 size_t io_len;
4189 u_offset_t io_off;
4190 uint_t blksz;
4191 rl_t *rl;
4192 int error = 0;
4193
4194 ZFS_ENTER(zfsvfs);
4195 ZFS_VERIFY_ZP(zp);
4320 (void) sa_update(zp->z_sa_hdl, SA_ZPL_ATIME(zfsvfs),
4321 (void *)&zp->z_atime, sizeof (zp->z_atime), tx);
4322 zp->z_atime_dirty = 0;
4323 mutex_exit(&zp->z_lock);
4324 dmu_tx_commit(tx);
4325 }
4326 }
4327
4328 zfs_zinactive(zp);
4329 rw_exit(&zfsvfs->z_teardown_inactive_lock);
4330 }
4331
4332 /*
4333 * Bounds-check the seek operation.
4334 *
4335 * IN: vp - vnode seeking within
4336 * ooff - old file offset
4337 * noffp - pointer to new file offset
4338 * ct - caller context
4339 *
4340 * RETURN: 0 on success, EINVAL if new offset invalid.
4341 */
4342 /* ARGSUSED */
4343 static int
4344 zfs_seek(vnode_t *vp, offset_t ooff, offset_t *noffp,
4345 caller_context_t *ct)
4346 {
4347 if (vp->v_type == VDIR)
4348 return (0);
4349 return ((*noffp < 0 || *noffp > MAXOFFSET_T) ? EINVAL : 0);
4350 }
4351
4352 /*
4353 * Pre-filter the generic locking function to trap attempts to place
4354 * a mandatory lock on a memory mapped file.
4355 */
4356 static int
4357 zfs_frlock(vnode_t *vp, int cmd, flock64_t *bfp, int flag, offset_t offset,
4358 flk_callback_t *flk_cbp, cred_t *cr, caller_context_t *ct)
4359 {
4360 znode_t *zp = VTOZ(vp);
4456 * Return pointers to the pages for the file region [off, off + len]
4457 * in the pl array. If plsz is greater than len, this function may
4458 * also return page pointers from after the specified region
4459 * (i.e. the region [off, off + plsz]). These additional pages are
4460 * only returned if they are already in the cache, or were created as
4461 * part of a klustered read.
4462 *
4463 * IN: vp - vnode of file to get data from.
4464 * off - position in file to get data from.
4465 * len - amount of data to retrieve.
4466 * plsz - length of provided page list.
4467 * seg - segment to obtain pages for.
4468 * addr - virtual address of fault.
4469 * rw - mode of created pages.
4470 * cr - credentials of caller.
4471 * ct - caller context.
4472 *
4473 * OUT: protp - protection mode of created pages.
4474 * pl - list of pages created.
4475 *
4476 * RETURN: 0 on success, error code on failure.
4477 *
4478 * Timestamps:
4479 * vp - atime updated
4480 */
4481 /* ARGSUSED */
4482 static int
4483 zfs_getpage(vnode_t *vp, offset_t off, size_t len, uint_t *protp,
4484 page_t *pl[], size_t plsz, struct seg *seg, caddr_t addr,
4485 enum seg_rw rw, cred_t *cr, caller_context_t *ct)
4486 {
4487 znode_t *zp = VTOZ(vp);
4488 zfsvfs_t *zfsvfs = zp->z_zfsvfs;
4489 page_t **pl0 = pl;
4490 int err = 0;
4491
4492 /* we do our own caching, faultahead is unnecessary */
4493 if (pl == NULL)
4494 return (0);
4495 else if (len > plsz)
4496 len = plsz;
4540 if (err) {
4541 /*
4542 * Release any pages we have previously locked.
4543 */
4544 while (pl > pl0)
4545 page_unlock(*--pl);
4546 } else {
4547 ZFS_ACCESSTIME_STAMP(zfsvfs, zp);
4548 }
4549
4550 *pl = NULL;
4551
4552 ZFS_EXIT(zfsvfs);
4553 return (err);
4554 }
4555
4556 /*
4557 * Request a memory map for a section of a file. This code interacts
4558 * with common code and the VM system as follows:
4559 *
4560 * - common code calls mmap(), which ends up in smmap_common()
4561 * - this calls VOP_MAP(), which takes you into (say) zfs
4562 * - zfs_map() calls as_map(), passing segvn_create() as the callback
4563 * - segvn_create() creates the new segment and calls VOP_ADDMAP()
4564 * - zfs_addmap() updates z_mapcnt
4565 */
4566 /*ARGSUSED*/
4567 static int
4568 zfs_map(vnode_t *vp, offset_t off, struct as *as, caddr_t *addrp,
4569 size_t len, uchar_t prot, uchar_t maxprot, uint_t flags, cred_t *cr,
4570 caller_context_t *ct)
4571 {
4572 znode_t *zp = VTOZ(vp);
4573 zfsvfs_t *zfsvfs = zp->z_zfsvfs;
4574 segvn_crargs_t vn_a;
4575 int error;
4576
4577 ZFS_ENTER(zfsvfs);
4578 ZFS_VERIFY_ZP(zp);
4579
4580 if ((prot & PROT_WRITE) && (zp->z_pflags &
4581 (ZFS_IMMUTABLE | ZFS_READONLY | ZFS_APPENDONLY))) {
4582 ZFS_EXIT(zfsvfs);
4583 return (SET_ERROR(EPERM));
4584 }
4686 vn_has_cached_data(vp))
4687 (void) VOP_PUTPAGE(vp, off, len, B_ASYNC, cr, ct);
4688
4689 return (0);
4690 }
4691
4692 /*
4693 * Free or allocate space in a file. Currently, this function only
4694 * supports the `F_FREESP' command. However, this command is somewhat
4695 * misnamed, as its functionality includes the ability to allocate as
4696 * well as free space.
4697 *
4698 * IN: vp - vnode of file to free data in.
4699 * cmd - action to take (only F_FREESP supported).
4700 * bfp - section of file to free/alloc.
4701 * flag - current file open mode flags.
4702 * offset - current file offset.
4703 * cr - credentials of caller [UNUSED].
4704 * ct - caller context.
4705 *
4706 * RETURN: 0 on success, error code on failure.
4707 *
4708 * Timestamps:
4709 * vp - ctime|mtime updated
4710 */
4711 /* ARGSUSED */
4712 static int
4713 zfs_space(vnode_t *vp, int cmd, flock64_t *bfp, int flag,
4714 offset_t offset, cred_t *cr, caller_context_t *ct)
4715 {
4716 znode_t *zp = VTOZ(vp);
4717 zfsvfs_t *zfsvfs = zp->z_zfsvfs;
4718 uint64_t off, len;
4719 int error;
4720
4721 ZFS_ENTER(zfsvfs);
4722 ZFS_VERIFY_ZP(zp);
4723
4724 if (cmd != F_FREESP) {
4725 ZFS_EXIT(zfsvfs);
4726 return (SET_ERROR(EINVAL));
4901 {
4902 znode_t *zp = VTOZ(vp);
4903 zfsvfs_t *zfsvfs = zp->z_zfsvfs;
4904 int error;
4905 boolean_t skipaclchk = (flag & ATTR_NOACLCHECK) ? B_TRUE : B_FALSE;
4906 zilog_t *zilog = zfsvfs->z_log;
4907
4908 ZFS_ENTER(zfsvfs);
4909 ZFS_VERIFY_ZP(zp);
4910
4911 error = zfs_setacl(zp, vsecp, skipaclchk, cr);
4912
4913 if (zfsvfs->z_os->os_sync == ZFS_SYNC_ALWAYS)
4914 zil_commit(zilog, 0);
4915
4916 ZFS_EXIT(zfsvfs);
4917 return (error);
4918 }
4919
4920 /*
4921 * The smallest read we may consider to loan out an arcbuf.
4922 * This must be a power of 2.
4923 */
4924 int zcr_blksz_min = (1 << 10); /* 1K */
4925 /*
4926 * If set to less than the file block size, allow loaning out of an
4927 * arcbuf for a partial block read. This must be a power of 2.
4928 */
4929 int zcr_blksz_max = (1 << 17); /* 128K */
4930
4931 /*ARGSUSED*/
4932 static int
4933 zfs_reqzcbuf(vnode_t *vp, enum uio_rw ioflag, xuio_t *xuio, cred_t *cr,
4934 caller_context_t *ct)
4935 {
4936 znode_t *zp = VTOZ(vp);
4937 zfsvfs_t *zfsvfs = zp->z_zfsvfs;
4938 int max_blksz = zfsvfs->z_max_blksz;
4939 uio_t *uio = &xuio->xu_uio;
4940 ssize_t size = uio->uio_resid;
4941 offset_t offset = uio->uio_loffset;
4942 int blksz;
4943 int fullblk, i;
4944 arc_buf_t *abuf;
4945 ssize_t maxsize;
4946 int preamble, postamble;
4947
4948 if (xuio->xu_type != UIOTYPE_ZEROCOPY)
5182 };
5183
5184 /*
5185 * special share hidden files vnode operations template
5186 */
5187 vnodeops_t *zfs_sharevnodeops;
5188 const fs_operation_def_t zfs_sharevnodeops_template[] = {
5189 VOPNAME_GETATTR, { .vop_getattr = zfs_getattr },
5190 VOPNAME_ACCESS, { .vop_access = zfs_access },
5191 VOPNAME_INACTIVE, { .vop_inactive = zfs_inactive },
5192 VOPNAME_FID, { .vop_fid = zfs_fid },
5193 VOPNAME_PATHCONF, { .vop_pathconf = zfs_pathconf },
5194 VOPNAME_GETSECATTR, { .vop_getsecattr = zfs_getsecattr },
5195 VOPNAME_SETSECATTR, { .vop_setsecattr = zfs_setsecattr },
5196 VOPNAME_VNEVENT, { .vop_vnevent = fs_vnevent_support },
5197 NULL, NULL
5198 };
5199
5200 /*
5201 * Extended attribute directory vnode operations template
5202 *
5203 * This template is identical to the directory vnodes
5204 * operation template except for restricted operations:
5205 * VOP_MKDIR()
5206 * VOP_SYMLINK()
5207 *
5208 * Note that there are other restrictions embedded in:
5209 * zfs_create() - restrict type to VREG
5210 * zfs_link() - no links into/out of attribute space
5211 * zfs_rename() - no moves into/out of attribute space
5212 */
5213 vnodeops_t *zfs_xdvnodeops;
5214 const fs_operation_def_t zfs_xdvnodeops_template[] = {
5215 VOPNAME_OPEN, { .vop_open = zfs_open },
5216 VOPNAME_CLOSE, { .vop_close = zfs_close },
5217 VOPNAME_IOCTL, { .vop_ioctl = zfs_ioctl },
5218 VOPNAME_GETATTR, { .vop_getattr = zfs_getattr },
5219 VOPNAME_SETATTR, { .vop_setattr = zfs_setattr },
5220 VOPNAME_ACCESS, { .vop_access = zfs_access },
5221 VOPNAME_LOOKUP, { .vop_lookup = zfs_lookup },
5222 VOPNAME_CREATE, { .vop_create = zfs_create },
5223 VOPNAME_REMOVE, { .vop_remove = zfs_remove },
5224 VOPNAME_LINK, { .vop_link = zfs_link },
5225 VOPNAME_RENAME, { .vop_rename = zfs_rename },
5226 VOPNAME_MKDIR, { .error = zfs_inval },
5227 VOPNAME_RMDIR, { .vop_rmdir = zfs_rmdir },
|