FreeBSD: Add posix_fadvise(POSIX_FADV_WILLNEED) support

As commit 320f0c6 did for Linux, connect POSIX_FADV_WILLNEED
up to dmu_prefetch() on FreeBSD.

While there, fix portability problems in tests/functional/fadvise.

1.  Instead of relying on the numerical values of POSIX_FADV_XXX macros,
    accept macro names as arguments to the file_fadvise program.  (The
    numbers happen to match on Linux and FreeBSD, but future systems may
    vary and it seems a little strange/raw to count on that.)

2.  For implementation reasons, SEQUENTIAL doesn't reach ZFS via FreeBSD
    VFS currently (perhaps something that should be investigated in
    FreeBSD).  Since on Linux we're treating SEQUENTIAL and WILLNEED the
    same, it doesn't really matter which one we use, so switch the test
    over to WILLNEED exercise the new prefetch code on both OSes the
    same way.

Reviewed-by: Mateusz Guzik <mjg@FreeBSD.org>
Reviewed-by: Fedor Uporov <fuporov.vstack@gmail.com>
Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov>
Reviewed-by: Alexander Motin <mav@FreeBSD.org>
Signed-off-by: Thomas Munro <tmunro@FreeBSD.org>
Co-authored-by: Alexander Motin <mav@FreeBSD.org>
Closes #17379
This commit is contained in:
Alexander Motin
2025-05-29 09:34:07 -04:00
committed by GitHub
parent 00360efa35
commit fa697b94e6
8 changed files with 119 additions and 14 deletions
+73
View File
@@ -6055,6 +6055,78 @@ zfs_freebsd_aclcheck(struct vop_aclcheck_args *ap)
return (EOPNOTSUPP);
}
#ifndef _SYS_SYSPROTO_H_
struct vop_advise_args {
struct vnode *a_vp;
off_t a_start;
off_t a_end;
int a_advice;
};
#endif
static int
zfs_freebsd_advise(struct vop_advise_args *ap)
{
vnode_t *vp = ap->a_vp;
off_t start = ap->a_start;
off_t end = ap->a_end;
int advice = ap->a_advice;
off_t len;
znode_t *zp;
zfsvfs_t *zfsvfs;
objset_t *os;
int error = 0;
if (end < start)
return (EINVAL);
error = vn_lock(vp, LK_SHARED);
if (error)
return (error);
zp = VTOZ(vp);
zfsvfs = zp->z_zfsvfs;
os = zp->z_zfsvfs->z_os;
if ((error = zfs_enter_verify_zp(zfsvfs, zp, FTAG)) != 0)
goto out_unlock;
/* kern_posix_fadvise points to the last byte, we want one past */
if (end != OFF_MAX)
end += 1;
len = end - start;
switch (advice) {
case POSIX_FADV_WILLNEED:
/*
* Pass on the caller's size directly, but note that
* dmu_prefetch_max will effectively cap it. If there really
* is a larger sequential access pattern, perhaps dmu_zfetch
* will detect it.
*/
dmu_prefetch(os, zp->z_id, 0, start, len,
ZIO_PRIORITY_ASYNC_READ);
break;
case POSIX_FADV_NORMAL:
case POSIX_FADV_RANDOM:
case POSIX_FADV_SEQUENTIAL:
case POSIX_FADV_DONTNEED:
case POSIX_FADV_NOREUSE:
/* ignored for now */
break;
default:
error = EINVAL;
break;
}
zfs_exit(zfsvfs, FTAG);
out_unlock:
VOP_UNLOCK(vp);
return (error);
}
static int
zfs_vptocnp(struct vop_vptocnp_args *ap)
{
@@ -6293,6 +6365,7 @@ struct vop_vector zfs_vnodeops = {
.vop_link = zfs_freebsd_link,
.vop_symlink = zfs_freebsd_symlink,
.vop_readlink = zfs_freebsd_readlink,
.vop_advise = zfs_freebsd_advise,
.vop_read = zfs_freebsd_read,
.vop_write = zfs_freebsd_write,
.vop_remove = zfs_freebsd_remove,