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 9d0887402b
  assumed 13.0 or later.
* FreeBSD 13.0 added copy_file_range, and OpenZFS change 67a1b03791
  assumed 13.0 or later.

Sponsored-by: Axcient
Reviewed-by: Alexander Motin <mav@FreeBSD.org>
Signed-off-by: Alan Somers <asomers@gmail.com>
Closes #15551
This commit is contained in:
Alan Somers 2023-11-27 13:58:03 -07:00 committed by GitHub
parent a490875103
commit 126efb5889
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 25 additions and 10 deletions

View File

@ -32,4 +32,4 @@ For more details see the NOTICE, LICENSE and COPYRIGHT files; `UCRL-CODE-235197`
# Supported Kernels # Supported Kernels
* The `META` file contains the officially recognized supported Linux kernel versions. * 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.

View File

@ -56,6 +56,7 @@ enum symfollow { NO_FOLLOW = NOFOLLOW };
#ifndef IN_BASE #ifndef IN_BASE
#include_next <sys/vnode.h> #include_next <sys/vnode.h>
#endif #endif
#include <sys/ccompat.h>
#include <sys/mount.h> #include <sys/mount.h>
#include <sys/cred.h> #include <sys/cred.h>
#include <sys/fcntl.h> #include <sys/fcntl.h>
@ -104,7 +105,7 @@ vn_flush_cached_data(vnode_t *vp, boolean_t sync)
zfs_vmobject_wlock(vp->v_object); zfs_vmobject_wlock(vp->v_object);
vm_object_page_clean(vp->v_object, 0, 0, flags); vm_object_page_clean(vp->v_object, 0, 0, flags);
zfs_vmobject_wunlock(vp->v_object); zfs_vmobject_wunlock(vp->v_object);
VOP_UNLOCK(vp); VOP_UNLOCK1(vp);
} }
} }
#endif #endif

View File

@ -29,11 +29,7 @@
#include <sys/kmem.h> #include <sys/kmem.h>
#include <sys/kmem_cache.h> #include <sys/kmem_cache.h>
#include <sys/zmod.h> #include <sys/zmod.h>
#if __FreeBSD_version >= 1300041
#include <contrib/zlib/zlib.h> #include <contrib/zlib/zlib.h>
#else
#include <sys/zlib.h>
#endif
#include <sys/kobj.h> #include <sys/kobj.h>
@ -87,11 +83,7 @@ zlib_inflateInit(z_stream *stream)
static int static int
zlib_inflate(z_stream *stream, int finish) zlib_inflate(z_stream *stream, int finish)
{ {
#if __FreeBSD_version >= 1300024
return (inflate(stream, finish)); return (inflate(stream, finish));
#else
return (_zlib104_inflate(stream, finish));
#endif
} }

View File

@ -46,6 +46,7 @@ knlist_sx_xunlock(void *arg)
sx_xunlock((struct sx *)arg); sx_xunlock((struct sx *)arg);
} }
#if __FreeBSD_version >= 1300128
static void static void
knlist_sx_assert_lock(void *arg, int what) knlist_sx_assert_lock(void *arg, int what)
{ {
@ -55,11 +56,28 @@ knlist_sx_assert_lock(void *arg, int what)
else else
sx_assert((struct sx *)arg, SX_UNLOCKED); 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 void
knlist_init_sx(struct knlist *knl, struct sx *lock) knlist_init_sx(struct knlist *knl, struct sx *lock)
{ {
#if __FreeBSD_version >= 1300128
knlist_init(knl, lock, knlist_sx_xlock, knlist_sx_xunlock, knlist_init(knl, lock, knlist_sx_xlock, knlist_sx_xunlock,
knlist_sx_assert_lock); knlist_sx_assert_lock);
#else
knlist_init(knl, lock, knlist_sx_xlock, knlist_sx_xunlock,
knlist_sx_assert_locked, knlist_sx_assert_unlocked);
#endif
} }

View File

@ -6220,6 +6220,7 @@ zfs_deallocate(struct vop_deallocate_args *ap)
} }
#endif #endif
#if __FreeBSD_version >= 1300039
#ifndef _SYS_SYSPROTO_H_ #ifndef _SYS_SYSPROTO_H_
struct vop_copy_file_range_args { struct vop_copy_file_range_args {
struct vnode *a_invp; struct vnode *a_invp;
@ -6326,6 +6327,7 @@ bad_write_fallback:
ap->a_incred, ap->a_outcred, ap->a_fsizetd); ap->a_incred, ap->a_outcred, ap->a_fsizetd);
return (error); return (error);
} }
#endif
struct vop_vector zfs_vnodeops; struct vop_vector zfs_vnodeops;
struct vop_vector zfs_fifoops; struct vop_vector zfs_fifoops;
@ -6390,7 +6392,9 @@ struct vop_vector zfs_vnodeops = {
#if __FreeBSD_version >= 1400043 #if __FreeBSD_version >= 1400043
.vop_add_writecount = vop_stdadd_writecount_nomsync, .vop_add_writecount = vop_stdadd_writecount_nomsync,
#endif #endif
#if __FreeBSD_version >= 1300039
.vop_copy_file_range = zfs_freebsd_copy_file_range, .vop_copy_file_range = zfs_freebsd_copy_file_range,
#endif
}; };
VFS_VOP_VECTOR_REGISTER(zfs_vnodeops); VFS_VOP_VECTOR_REGISTER(zfs_vnodeops);