From 349fb77f1167c287e9d2bf8bab5f1934d8b2672c Mon Sep 17 00:00:00 2001 From: Alan Somers Date: Mon, 27 Nov 2023 13:58:03 -0700 Subject: [PATCH] FreeBSD: Fix the build on FreeBSD 12 It was broken for several reasons: * VOP_UNLOCK lost an argument in 13.0. So OpenZFS should be using VOP_UNLOCK1, but a few direct calls to VOP_UNLOCK snuck in. * The location of the zlib header moved in 13.0 and 12.1. We can drop support for building on 12.0, which is EoL. * knlist_init lost an argument in 13.0. OpenZFS change 9d0887402ba assumed 13.0 or later. * FreeBSD 13.0 added copy_file_range, and OpenZFS change 67a1b037915 assumed 13.0 or later. Sponsored-by: Axcient Reviewed-by: Alexander Motin Signed-off-by: Alan Somers Closes #15551 --- README.md | 2 +- include/os/freebsd/spl/sys/vnode.h | 3 ++- module/os/freebsd/spl/spl_zlib.c | 8 -------- module/os/freebsd/zfs/event_os.c | 18 ++++++++++++++++++ module/os/freebsd/zfs/zfs_vnops_os.c | 4 ++++ 5 files changed, 25 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index 3318895609..af244c1fff 100644 --- a/README.md +++ b/README.md @@ -32,4 +32,4 @@ For more details see the NOTICE, LICENSE and COPYRIGHT files; `UCRL-CODE-235197` # Supported Kernels * The `META` file contains the officially recognized supported Linux kernel versions. - * Supported FreeBSD versions are any supported branches and releases starting from 12.2-RELEASE. + * Supported FreeBSD versions are any supported branches and releases starting from 12.4-RELEASE. diff --git a/include/os/freebsd/spl/sys/vnode.h b/include/os/freebsd/spl/sys/vnode.h index 0779e58e49..75c32f221f 100644 --- a/include/os/freebsd/spl/sys/vnode.h +++ b/include/os/freebsd/spl/sys/vnode.h @@ -56,6 +56,7 @@ enum symfollow { NO_FOLLOW = NOFOLLOW }; #ifndef IN_BASE #include_next #endif +#include #include #include #include @@ -104,7 +105,7 @@ vn_flush_cached_data(vnode_t *vp, boolean_t sync) zfs_vmobject_wlock(vp->v_object); vm_object_page_clean(vp->v_object, 0, 0, flags); zfs_vmobject_wunlock(vp->v_object); - VOP_UNLOCK(vp); + VOP_UNLOCK1(vp); } } #endif diff --git a/module/os/freebsd/spl/spl_zlib.c b/module/os/freebsd/spl/spl_zlib.c index 8bd3bdedf2..42c6d7f9df 100644 --- a/module/os/freebsd/spl/spl_zlib.c +++ b/module/os/freebsd/spl/spl_zlib.c @@ -32,11 +32,7 @@ __FBSDID("$FreeBSD$"); #include #include #include -#if __FreeBSD_version >= 1300041 #include -#else -#include -#endif #include @@ -90,11 +86,7 @@ zlib_inflateInit(z_stream *stream) static int zlib_inflate(z_stream *stream, int finish) { -#if __FreeBSD_version >= 1300024 return (inflate(stream, finish)); -#else - return (_zlib104_inflate(stream, finish)); -#endif } diff --git a/module/os/freebsd/zfs/event_os.c b/module/os/freebsd/zfs/event_os.c index 239d44d0cf..e774fbaaf8 100644 --- a/module/os/freebsd/zfs/event_os.c +++ b/module/os/freebsd/zfs/event_os.c @@ -46,6 +46,7 @@ knlist_sx_xunlock(void *arg) sx_xunlock((struct sx *)arg); } +#if __FreeBSD_version >= 1300128 static void knlist_sx_assert_lock(void *arg, int what) { @@ -55,11 +56,28 @@ knlist_sx_assert_lock(void *arg, int what) else sx_assert((struct sx *)arg, SX_UNLOCKED); } +#else +static void +knlist_sx_assert_locked(void *arg) +{ + sx_assert((struct sx *)arg, SX_LOCKED); +} +static void +knlist_sx_assert_unlocked(void *arg) +{ + sx_assert((struct sx *)arg, SX_UNLOCKED); +} +#endif void knlist_init_sx(struct knlist *knl, struct sx *lock) { +#if __FreeBSD_version >= 1300128 knlist_init(knl, lock, knlist_sx_xlock, knlist_sx_xunlock, knlist_sx_assert_lock); +#else + knlist_init(knl, lock, knlist_sx_xlock, knlist_sx_xunlock, + knlist_sx_assert_locked, knlist_sx_assert_unlocked); +#endif } diff --git a/module/os/freebsd/zfs/zfs_vnops_os.c b/module/os/freebsd/zfs/zfs_vnops_os.c index f672deed34..05f28033be 100644 --- a/module/os/freebsd/zfs/zfs_vnops_os.c +++ b/module/os/freebsd/zfs/zfs_vnops_os.c @@ -6213,6 +6213,7 @@ zfs_deallocate(struct vop_deallocate_args *ap) } #endif +#if __FreeBSD_version >= 1300039 #ifndef _SYS_SYSPROTO_H_ struct vop_copy_file_range_args { struct vnode *a_invp; @@ -6319,6 +6320,7 @@ bad_write_fallback: ap->a_incred, ap->a_outcred, ap->a_fsizetd); return (error); } +#endif struct vop_vector zfs_vnodeops; struct vop_vector zfs_fifoops; @@ -6383,7 +6385,9 @@ struct vop_vector zfs_vnodeops = { #if __FreeBSD_version >= 1400043 .vop_add_writecount = vop_stdadd_writecount_nomsync, #endif +#if __FreeBSD_version >= 1300039 .vop_copy_file_range = zfs_freebsd_copy_file_range, +#endif }; VFS_VOP_VECTOR_REGISTER(zfs_vnodeops);