summaryrefslogtreecommitdiffstats
path: root/include/os
diff options
context:
space:
mode:
authorMatthew Macy <[email protected]>2020-07-25 20:09:50 -0700
committerGitHub <[email protected]>2020-07-25 20:09:50 -0700
commite64cc4954c7862db6a6b4dc978a091ebc3f870da (patch)
treec4338faa05d73ed93d55b4a775edf93ab15e99f7 /include/os
parent6d8da84106de1fc8480e1758cc88e81393b4c0c2 (diff)
Refactor ccompile.h to not include system headers
This is a step toward being able to vendor the OpenZFS code in FreeBSD. Reviewed-by: Brian Behlendorf <[email protected]> Reviewed-by: Ryan Moeller <[email protected]> Signed-off-by: Matt Macy <[email protected]> Closes #10625
Diffstat (limited to 'include/os')
-rw-r--r--include/os/freebsd/linux/types.h5
-rw-r--r--include/os/freebsd/spl/sys/ccompat.h138
-rw-r--r--include/os/freebsd/spl/sys/ccompile.h137
-rw-r--r--include/os/freebsd/spl/sys/condvar.h1
-rw-r--r--include/os/freebsd/spl/sys/kstat.h1
-rw-r--r--include/os/freebsd/spl/sys/param.h7
-rw-r--r--include/os/freebsd/spl/sys/systm.h2
-rw-r--r--include/os/freebsd/spl/sys/types.h17
-rw-r--r--include/os/freebsd/zfs/sys/zfs_context_os.h3
9 files changed, 175 insertions, 136 deletions
diff --git a/include/os/freebsd/linux/types.h b/include/os/freebsd/linux/types.h
index 301163c03..d290317cc 100644
--- a/include/os/freebsd/linux/types.h
+++ b/include/os/freebsd/linux/types.h
@@ -31,9 +31,6 @@
#ifndef _LINUX_TYPES_H_
#define _LINUX_TYPES_H_
-#include <sys/cdefs.h>
-#include <sys/types.h>
-#include <sys/systm.h>
#include <linux/compiler.h>
@@ -53,7 +50,7 @@ typedef uint64_t __le64;
typedef uint64_t __be64;
typedef unsigned gfp_t;
-typedef uint64_t loff_t;
+typedef off_t loff_t;
typedef vm_paddr_t resource_size_t;
typedef uint16_t __bitwise__ __sum16;
typedef unsigned long pgoff_t;
diff --git a/include/os/freebsd/spl/sys/ccompat.h b/include/os/freebsd/spl/sys/ccompat.h
new file mode 100644
index 000000000..6c8767635
--- /dev/null
+++ b/include/os/freebsd/spl/sys/ccompat.h
@@ -0,0 +1,138 @@
+/*
+ * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * $FreeBSD$
+ */
+
+#ifndef _SYS_CCOMPAT_H
+#define _SYS_CCOMPAT_H
+
+#if __FreeBSD_version < 1300051
+#define vm_page_valid(m) (m)->valid = VM_PAGE_BITS_ALL
+#define vm_page_do_sunbusy(m)
+#define vm_page_none_valid(m) ((m)->valid == 0)
+#else
+#define vm_page_do_sunbusy(m) vm_page_sunbusy(m)
+#endif
+
+#if __FreeBSD_version < 1300074
+#define VOP_UNLOCK1(x) VOP_UNLOCK(x, 0)
+#else
+#define VOP_UNLOCK1(x) VOP_UNLOCK(x)
+#endif
+
+#if __FreeBSD_version < 1300064
+#define VN_IS_DOOMED(vp) ((vp)->v_iflag & VI_DOOMED)
+#endif
+
+#if __FreeBSD_version < 1300068
+#define VFS_VOP_VECTOR_REGISTER(x)
+#endif
+
+#if __FreeBSD_version >= 1300076
+#define getnewvnode_reserve_() getnewvnode_reserve()
+#else
+#define getnewvnode_reserve_() getnewvnode_reserve(1)
+#endif
+struct hlist_node {
+ struct hlist_node *next, **pprev;
+};
+
+struct hlist_head {
+ struct hlist_node *first;
+};
+
+typedef struct {
+ volatile int counter;
+} atomic_t;
+
+ /* BEGIN CSTYLED */
+#define hlist_for_each(p, head) \
+ for (p = (head)->first; p; p = (p)->next)
+
+#define hlist_entry(ptr, type, field) container_of(ptr, type, field)
+
+#define container_of(ptr, type, member) \
+({ \
+ const __typeof(((type *)0)->member) *__p = (ptr); \
+ (type *)((uintptr_t)__p - offsetof(type, member)); \
+})
+ /* END CSTYLED */
+
+static inline void
+hlist_add_head(struct hlist_node *n, struct hlist_head *h)
+{
+ n->next = h->first;
+ if (h->first != NULL)
+ h->first->pprev = &n->next;
+ WRITE_ONCE(h->first, n);
+ n->pprev = &h->first;
+}
+
+static inline void
+hlist_del(struct hlist_node *n)
+{
+ WRITE_ONCE(*(n->pprev), n->next);
+ if (n->next != NULL)
+ n->next->pprev = n->pprev;
+}
+ /* BEGIN CSTYLED */
+#define READ_ONCE(x) ({ \
+ __typeof(x) __var = ({ \
+ barrier(); \
+ ACCESS_ONCE(x); \
+ }); \
+ barrier(); \
+ __var; \
+})
+
+#define HLIST_HEAD_INIT { }
+#define HLIST_HEAD(name) struct hlist_head name = HLIST_HEAD_INIT
+#define INIT_HLIST_HEAD(head) (head)->first = NULL
+
+#define INIT_HLIST_NODE(node) \
+ do { \
+ (node)->next = NULL; \
+ (node)->pprev = NULL; \
+ } while (0)
+
+/* END CSTYLED */
+static inline int
+atomic_read(const atomic_t *v)
+{
+ return (READ_ONCE(v->counter));
+}
+
+static inline int
+atomic_inc(atomic_t *v)
+{
+ return (atomic_fetchadd_int(&v->counter, 1) + 1);
+}
+
+static inline int
+atomic_dec(atomic_t *v)
+{
+ return (atomic_fetchadd_int(&v->counter, -1) - 1);
+}
+#endif
diff --git a/include/os/freebsd/spl/sys/ccompile.h b/include/os/freebsd/spl/sys/ccompile.h
index 116612b61..cfb94268b 100644
--- a/include/os/freebsd/spl/sys/ccompile.h
+++ b/include/os/freebsd/spl/sys/ccompile.h
@@ -164,14 +164,19 @@ extern "C" {
#define KMALLOC_MAX_SIZE MAXPHYS
-#ifdef _KERNEL
-#if !defined(LOCORE) && !defined(_ASM)
-typedef unsigned long long u_longlong_t;
-typedef long long longlong_t;
-
+#ifndef LOCORE
+#ifndef HAVE_RPC_TYPES
+typedef int bool_t;
+typedef int enum_t;
+#endif
+#endif
-typedef void zfs_kernel_param_t;
+#ifndef __cplusplus
+#define __init
+#define __exit
#endif
+
+#ifdef _KERNEL
#define param_set_charp(a, b) (0)
#define ATTR_UID AT_UID
#define ATTR_GID AT_GID
@@ -186,127 +191,7 @@ typedef void zfs_kernel_param_t;
#define MUTEX_NOLOCKDEP 0
#define RW_NOLOCKDEP 0
-#if !defined(LOCORE) && !defined(_ASM)
-#include <sys/param.h>
-#include <linux/types.h>
-
-#if __FreeBSD_version < 1300051
-#define vm_page_valid(m) (m)->valid = VM_PAGE_BITS_ALL
-#define vm_page_do_sunbusy(m)
-#define vm_page_none_valid(m) ((m)->valid == 0)
-#else
-#define vm_page_do_sunbusy(m) vm_page_sunbusy(m)
-#endif
-
-#if __FreeBSD_version < 1300074
-#define VOP_UNLOCK1(x) VOP_UNLOCK(x, 0)
#else
-#define VOP_UNLOCK1(x) VOP_UNLOCK(x)
-#endif
-
-#if __FreeBSD_version < 1300064
-#define VN_IS_DOOMED(vp) ((vp)->v_iflag & VI_DOOMED)
-#endif
-
-#if __FreeBSD_version < 1300068
-#define VFS_VOP_VECTOR_REGISTER(x)
-#endif
-
-#if __FreeBSD_version >= 1300076
-#define getnewvnode_reserve_() getnewvnode_reserve()
-#else
-#define getnewvnode_reserve_() getnewvnode_reserve(1)
-#endif
-struct hlist_node {
- struct hlist_node *next, **pprev;
-};
-
-struct hlist_head {
- struct hlist_node *first;
-};
-
-typedef struct {
- volatile int counter;
-} atomic_t;
-
- /* BEGIN CSTYLED */
-#define hlist_for_each(p, head) \
- for (p = (head)->first; p; p = (p)->next)
-
-#define hlist_entry(ptr, type, field) container_of(ptr, type, field)
-
-#define container_of(ptr, type, member) \
-({ \
- const __typeof(((type *)0)->member) *__p = (ptr); \
- (type *)((uintptr_t)__p - offsetof(type, member)); \
-})
- /* END CSTYLED */
-
-static inline void
-hlist_add_head(struct hlist_node *n, struct hlist_head *h)
-{
- n->next = h->first;
- if (h->first != NULL)
- h->first->pprev = &n->next;
- WRITE_ONCE(h->first, n);
- n->pprev = &h->first;
-}
-
-static inline void
-hlist_del(struct hlist_node *n)
-{
- WRITE_ONCE(*(n->pprev), n->next);
- if (n->next != NULL)
- n->next->pprev = n->pprev;
-}
- /* BEGIN CSTYLED */
-#define READ_ONCE(x) ({ \
- __typeof(x) __var = ({ \
- barrier(); \
- ACCESS_ONCE(x); \
- }); \
- barrier(); \
- __var; \
-})
-
-#define HLIST_HEAD_INIT { }
-#define HLIST_HEAD(name) struct hlist_head name = HLIST_HEAD_INIT
-#define INIT_HLIST_HEAD(head) (head)->first = NULL
-
-#define INIT_HLIST_NODE(node) \
- do { \
- (node)->next = NULL; \
- (node)->pprev = NULL; \
- } while (0)
-
-/* END CSTYLED */
-static inline int
-atomic_read(const atomic_t *v)
-{
- return (READ_ONCE(v->counter));
-}
-
-static inline int
-atomic_inc(atomic_t *v)
-{
- return (atomic_fetchadd_int(&v->counter, 1) + 1);
-}
-
-static inline int
-atomic_dec(atomic_t *v)
-{
- return (atomic_fetchadd_int(&v->counter, -1) - 1);
-}
-#endif
-#else
-typedef long loff_t;
-typedef long rlim64_t;
-typedef int bool_t;
-typedef int enum_t;
-#ifndef __cplusplus
-#define __init
-#endif
-#define __exit
#define FALSE 0
#define TRUE 1
/*
diff --git a/include/os/freebsd/spl/sys/condvar.h b/include/os/freebsd/spl/sys/condvar.h
index 2e99a1a34..a42995793 100644
--- a/include/os/freebsd/spl/sys/condvar.h
+++ b/include/os/freebsd/spl/sys/condvar.h
@@ -31,6 +31,7 @@
#define _OPENSOLARIS_SYS_CONDVAR_H_
#include <sys/param.h>
+#include <sys/systm.h>
#include <sys/spl_condvar.h>
#include <sys/mutex.h>
diff --git a/include/os/freebsd/spl/sys/kstat.h b/include/os/freebsd/spl/sys/kstat.h
index 740f24b70..74c3da8ec 100644
--- a/include/os/freebsd/spl/sys/kstat.h
+++ b/include/os/freebsd/spl/sys/kstat.h
@@ -24,6 +24,7 @@
#ifndef _SPL_KSTAT_H
#define _SPL_KSTAT_H
+#include <sys/types.h>
#include <sys/sysctl.h>
struct list_head {};
#include <sys/mutex.h>
diff --git a/include/os/freebsd/spl/sys/param.h b/include/os/freebsd/spl/sys/param.h
index 01392dd67..92724e332 100644
--- a/include/os/freebsd/spl/sys/param.h
+++ b/include/os/freebsd/spl/sys/param.h
@@ -30,9 +30,12 @@
#ifndef _COMPAT_OPENSOLARIS_SYS_PARAM_H_
#define _COMPAT_OPENSOLARIS_SYS_PARAM_H_
+#include <sys/types.h>
#include_next <sys/param.h>
-
#define PAGESIZE PAGE_SIZE
#define ptob(x) ((uint64_t)(x) << PAGE_SHIFT)
-
+#ifdef _KERNEL
+#include <sys/systm.h>
+#include <sys/libkern.h>
+#endif
#endif
diff --git a/include/os/freebsd/spl/sys/systm.h b/include/os/freebsd/spl/sys/systm.h
index 53cc6f527..98ee95575 100644
--- a/include/os/freebsd/spl/sys/systm.h
+++ b/include/os/freebsd/spl/sys/systm.h
@@ -29,7 +29,7 @@
#ifndef _OPENSOLARIS_SYS_SYSTM_H_
#define _OPENSOLARIS_SYS_SYSTM_H_
-#include <sys/param.h>
+#include <sys/endian.h>
#include_next <sys/systm.h>
#include <sys/string.h>
diff --git a/include/os/freebsd/spl/sys/types.h b/include/os/freebsd/spl/sys/types.h
index ed5e8ef80..c06c963d6 100644
--- a/include/os/freebsd/spl/sys/types.h
+++ b/include/os/freebsd/spl/sys/types.h
@@ -33,18 +33,29 @@
/*
* This is a bag of dirty hacks to keep things compiling.
*/
+#include_next <sys/types.h>
+#ifdef __ILP32__
+typedef __uint64_t u_longlong_t;
+typedef __int64_t longlong_t;
+#else
+typedef unsigned long long u_longlong_t;
+typedef long long longlong_t;
+#endif
#include <sys/stdint.h>
-typedef int64_t clock_t;
#define _CLOCK_T_DECLARED
-#include_next <sys/types.h>
#include <sys/types32.h>
#include <sys/_stdarg.h>
+#include <linux/types.h>
#define MAXNAMELEN 256
+
+
+typedef void zfs_kernel_param_t;
+
typedef struct timespec timestruc_t;
typedef struct timespec timespec_t;
typedef struct timespec inode_timespec_t;
@@ -93,5 +104,5 @@ typedef u_longlong_t len_t;
typedef longlong_t diskaddr_t;
-
+#include <sys/debug.h>
#endif /* !_OPENSOLARIS_SYS_TYPES_H_ */
diff --git a/include/os/freebsd/zfs/sys/zfs_context_os.h b/include/os/freebsd/zfs/sys/zfs_context_os.h
index 529ba7204..8da3374a6 100644
--- a/include/os/freebsd/zfs/sys/zfs_context_os.h
+++ b/include/os/freebsd/zfs/sys/zfs_context_os.h
@@ -37,6 +37,9 @@
#include <sys/kdb.h>
#include <sys/pathname.h>
#include <sys/conf.h>
+#include <sys/types.h>
+#include <sys/ccompat.h>
+#include <linux/types.h>
#define cv_wait_io(cv, mp) cv_wait(cv, mp)
#define cv_wait_io_sig(cv, mp) cv_wait_sig(cv, mp)