Skip to content

Commit 178bcd7

Browse files
mattmacyRyan Moeller
authored andcommitted
Add FreeBSD support to OpenZFS
- Import FreeBSD specific parts Signed-off-by: Matt Macy <[email protected]> Co-authored-by: Ryan Moeller <[email protected]> Signed-off-by: Ryan Moeller <[email protected]> Requires-builders: amazon2, debian10, freebsd12, freebsd13, style
1 parent 5a42ef0 commit 178bcd7

File tree

214 files changed

+46969
-74
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

214 files changed

+46969
-74
lines changed

.github/suppressions.txt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
11
preprocessorErrorDirective:./module/zfs/vdev_raidz_math_avx512f.c:243
22
preprocessorErrorDirective:./module/zfs/vdev_raidz_math_sse2.c:266
3-
3+
uninitvar:module/os/freebsd/zfs/vdev_geom.c
4+
uninitvar:module/os/freebsd/zfs/zfs_vfsops.c
5+
uninitvar:module/os/freebsd/spl/spl_zone.c
6+
uninitvar:lib/libzutil/os/freebsd/zutil_import_os.c

.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,4 +62,9 @@ cscope.*
6262
*.patch
6363
*.orig
6464
*.log
65+
*.tmp
6566
venv
67+
68+
*.so
69+
*.so.debug
70+
*.so.full

Makefile.am

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,8 +104,9 @@ commitcheck:
104104
fi
105105

106106
cstyle:
107-
@find ${top_srcdir} -name build -prune -o -name '*.[hc]' \
108-
! -name 'zfs_config.*' ! -name '*.mod.c' -type f \
107+
@find ${top_srcdir} -name build -prune -o -type f -name '*.[hc]' \
108+
! -name 'zfs_config.*' ! -name '*.mod.c' \
109+
! -name 'opt_global.h' ! -name '*_if*.h' \
109110
-exec ${top_srcdir}/scripts/cstyle.pl -cpP {} \+
110111

111112
filter_executable = -exec test -x '{}' \; -print

README.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,6 @@ This repository contains the code for running OpenZFS on Linux and FreeBSD.
1919
Full documentation for installing OpenZFS on your favorite Linux distribution can
2020
be found at the [ZoL Site](https://zfsonlinux.org/).
2121

22-
FreeBSD support is a work in progress. See the [PR](https://github.com/openzfs/zfs/pull/8987).
23-
2422
# Contribute & Develop
2523

2624
We have a separate document with [contribution guidelines](./.github/CONTRIBUTING.md).
@@ -34,3 +32,4 @@ For more details see the NOTICE, LICENSE and COPYRIGHT files; `UCRL-CODE-235197`
3432

3533
# Supported Kernels
3634
* The `META` file contains the officially recognized supported Linux kernel versions.
35+
* Supported FreeBSD versions are 12-STABLE and 13-CURRENT.

cmd/Makefile.am

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
SUBDIRS = zfs zpool zdb zhack zinject zstreamdump ztest
2-
SUBDIRS += fsck_zfs vdev_id raidz_test zgenhostid
2+
SUBDIRS += fsck_zfs vdev_id raidz_test
33

44
if USING_PYTHON
55
SUBDIRS += arcstat arc_summary dbufstat
66
endif
77

88
if BUILD_LINUX
9-
SUBDIRS += mount_zfs zed zvol_id zvol_wait
9+
SUBDIRS += mount_zfs zed zgenhostid zvol_id zvol_wait
1010
endif

cmd/zpool/Makefile.am

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@ zpool_SOURCES = \
1111
zpool_util.h \
1212
zpool_vdev.c
1313

14+
if BUILD_FREEBSD
15+
zpool_SOURCES += os/freebsd/zpool_vdev_os.c
16+
endif
17+
1418
if BUILD_LINUX
1519
zpool_SOURCES += os/linux/zpool_vdev_os.c
1620
endif
@@ -20,6 +24,9 @@ zpool_LDADD = \
2024
$(top_builddir)/lib/libuutil/libuutil.la \
2125
$(top_builddir)/lib/libzfs/libzfs.la
2226

27+
if BUILD_FREEBSD
28+
zpool_LDADD += -L/usr/local/lib -lintl -lgeom
29+
endif
2330
zpool_LDADD += -lm $(LIBBLKID)
2431

2532
zpoolconfdir = $(sysconfdir)/zfs/zpool.d

cmd/zpool/os/freebsd/zpool_vdev_os.c

Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
/*
2+
* CDDL HEADER START
3+
*
4+
* The contents of this file are subject to the terms of the
5+
* Common Development and Distribution License (the "License").
6+
* You may not use this file except in compliance with the License.
7+
*
8+
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9+
* or http://www.opensolaris.org/os/licensing.
10+
* See the License for the specific language governing permissions
11+
* and limitations under the License.
12+
*
13+
* When distributing Covered Code, include this CDDL HEADER in each
14+
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15+
* If applicable, add the following below this CDDL HEADER, with the
16+
* fields enclosed by brackets "[]" replaced with your own identifying
17+
* information: Portions Copyright [yyyy] [name of copyright owner]
18+
*
19+
* CDDL HEADER END
20+
*/
21+
22+
/*
23+
* Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
24+
* Copyright (c) 2013, 2018 by Delphix. All rights reserved.
25+
* Copyright (c) 2016, 2017 Intel Corporation.
26+
* Copyright 2016 Igor Kozhukhov <[email protected]>.
27+
*/
28+
29+
/*
30+
* Functions to convert between a list of vdevs and an nvlist representing the
31+
* configuration. Each entry in the list can be one of:
32+
*
33+
* Device vdevs
34+
* disk=(path=..., devid=...)
35+
* file=(path=...)
36+
*
37+
* Group vdevs
38+
* raidz[1|2]=(...)
39+
* mirror=(...)
40+
*
41+
* Hot spares
42+
*
43+
* While the underlying implementation supports it, group vdevs cannot contain
44+
* other group vdevs. All userland verification of devices is contained within
45+
* this file. If successful, the nvlist returned can be passed directly to the
46+
* kernel; we've done as much verification as possible in userland.
47+
*
48+
* Hot spares are a special case, and passed down as an array of disk vdevs, at
49+
* the same level as the root of the vdev tree.
50+
*
51+
* The only function exported by this file is 'make_root_vdev'. The
52+
* function performs several passes:
53+
*
54+
* 1. Construct the vdev specification. Performs syntax validation and
55+
* makes sure each device is valid.
56+
* 2. Check for devices in use. Using libdiskmgt, makes sure that no
57+
* devices are also in use. Some can be overridden using the 'force'
58+
* flag, others cannot.
59+
* 3. Check for replication errors if the 'force' flag is not specified.
60+
* validates that the replication level is consistent across the
61+
* entire pool.
62+
* 4. Call libzfs to label any whole disks with an EFI label.
63+
*/
64+
65+
#include <assert.h>
66+
#include <errno.h>
67+
#include <fcntl.h>
68+
#include <libintl.h>
69+
#include <libnvpair.h>
70+
#include <libzutil.h>
71+
#include <limits.h>
72+
#include <sys/spa.h>
73+
#include <stdio.h>
74+
#include <string.h>
75+
#include <unistd.h>
76+
#include <paths.h>
77+
#include <sys/stat.h>
78+
#include <sys/disk.h>
79+
#include <sys/mntent.h>
80+
#include <libgeom.h>
81+
82+
#include "zpool_util.h"
83+
#include <sys/zfs_context.h>
84+
85+
int
86+
check_device(const char *name, boolean_t force, boolean_t isspare,
87+
boolean_t iswholedisk)
88+
{
89+
char path[MAXPATHLEN];
90+
91+
if (strncmp(name, _PATH_DEV, sizeof (_PATH_DEV) - 1) != 0)
92+
snprintf(path, sizeof (path), "%s%s", _PATH_DEV, name);
93+
else
94+
strlcpy(path, name, sizeof (path));
95+
96+
return (check_file(path, force, isspare));
97+
}
98+
99+
boolean_t
100+
check_sector_size_database(char *path, int *sector_size)
101+
{
102+
return (0);
103+
}
104+
105+
void
106+
zpool_vdev_enable_file(struct stat64 *statbuf, boolean_t *wholedisk)
107+
{
108+
if (S_ISCHR(statbuf->st_mode)) {
109+
statbuf->st_mode &= ~S_IFCHR;
110+
statbuf->st_mode |= S_IFBLK;
111+
*wholedisk = B_FALSE;
112+
}
113+
}

cmd/zpool/zpool_vdev.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -941,6 +941,10 @@ make_disks(zpool_handle_t *zhp, nvlist_t *nv)
941941
if (fd == -1) {
942942
if (errno == EBUSY)
943943
is_exclusive = 1;
944+
#ifdef __FreeBSD__
945+
if (errno == EPERM)
946+
is_exclusive = 1;
947+
#endif
944948
} else {
945949
(void) close(fd);
946950
}

config/Rules.am

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,26 +14,48 @@ DEFAULT_INCLUDES += \
1414
-I$(top_srcdir)/lib/libspl/include/os/linux
1515
endif
1616

17+
if BUILD_FREEBSD
18+
DEFAULT_INCLUDES += \
19+
-I$(top_srcdir)/lib/libspl/include/os/freebsd
20+
endif
21+
1722
AM_LIBTOOLFLAGS = --silent
1823

1924
AM_CFLAGS = -std=gnu99 -Wall -Wstrict-prototypes -fno-strict-aliasing
2025
AM_CFLAGS += $(NO_OMIT_FRAME_POINTER)
2126
AM_CFLAGS += $(DEBUG_CFLAGS)
2227
AM_CFLAGS += $(ASAN_CFLAGS)
23-
AM_CFLAGS += $(CODE_COVERAGE_CFLAGS)
28+
AM_CFLAGS += $(CODE_COVERAGE_CFLAGS) $(NO_FORMAT_ZERO_LENGTH)
29+
if BUILD_FREEBSD
30+
AM_CFLAGS += -fPIC -Werror -Wno-unknown-pragmas -Wno-enum-conversion
31+
AM_CFLAGS += -include $(top_srcdir)/include/os/freebsd/spl/sys/ccompile.h
32+
AM_CFLAGS += -I/usr/include -I/usr/local/include
33+
AM_CFLAGS += -D_MACHINE_ENDIAN_H_
34+
endif
2435

2536
AM_CPPFLAGS = -D_GNU_SOURCE
2637
AM_CPPFLAGS += -D_REENTRANT
2738
AM_CPPFLAGS += -D_FILE_OFFSET_BITS=64
2839
AM_CPPFLAGS += -D_LARGEFILE64_SOURCE
2940
AM_CPPFLAGS += -DHAVE_LARGE_STACKS=1
30-
AM_CPPFLAGS += -DTEXT_DOMAIN=\"zfs-linux-user\"
3141
AM_CPPFLAGS += -DLIBEXECDIR=\"$(libexecdir)\"
3242
AM_CPPFLAGS += -DRUNSTATEDIR=\"$(runstatedir)\"
3343
AM_CPPFLAGS += -DSBINDIR=\"$(sbindir)\"
3444
AM_CPPFLAGS += -DSYSCONFDIR=\"$(sysconfdir)\"
3545
AM_CPPFLAGS += $(DEBUG_CPPFLAGS)
3646
AM_CPPFLAGS += $(CODE_COVERAGE_CPPFLAGS)
47+
if BUILD_LINUX
48+
AM_CPPFLAGS += -DTEXT_DOMAIN=\"zfs-linux-user\"
49+
endif
50+
if BUILD_FREEBSD
51+
AM_CPPFLAGS += -DTEXT_DOMAIN=\"zfs-freebsd-user\"
52+
endif
3753

3854
AM_LDFLAGS = $(DEBUG_LDFLAGS)
3955
AM_LDFLAGS += $(ASAN_LDFLAGS)
56+
57+
if BUILD_FREEBSD
58+
AM_LDFLAGS += -fstack-protector-strong -shared
59+
AM_LDFLAGS += -Wl,-x -Wl,--fatal-warnings -Wl,--warn-shared-textrel
60+
AM_LDFLAGS += -lm
61+
endif

config/always-arch.m4

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ AC_DEFUN([ZFS_AC_CONFIG_ALWAYS_ARCH], [
1717
i?86)
1818
TARGET_CPU=i386
1919
;;
20-
x86_64)
20+
amd64|x86_64)
2121
TARGET_CPU=x86_64
2222
;;
2323
powerpc*)

config/always-compiler-options.m4

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,27 @@ AC_DEFUN([ZFS_AC_CONFIG_ALWAYS_CC_NO_FORMAT_TRUNCATION], [
8787
AC_SUBST([NO_FORMAT_TRUNCATION])
8888
])
8989

90+
dnl #
91+
dnl # Check if gcc supports -Wno-format-truncation option.
92+
dnl #
93+
AC_DEFUN([ZFS_AC_CONFIG_ALWAYS_CC_NO_FORMAT_ZERO_LENGTH], [
94+
AC_MSG_CHECKING([whether $CC supports -Wno-format-zero-length])
95+
96+
saved_flags="$CFLAGS"
97+
CFLAGS="$CFLAGS -Werror -Wno-format-zero-length"
98+
99+
AC_COMPILE_IFELSE([AC_LANG_PROGRAM([], [])], [
100+
NO_FORMAT_ZERO_LENGTH=-Wno-format-zero-length
101+
AC_MSG_RESULT([yes])
102+
], [
103+
NO_FORMAT_ZERO_LENGTH=
104+
AC_MSG_RESULT([no])
105+
])
106+
107+
CFLAGS="$saved_flags"
108+
AC_SUBST([NO_FORMAT_ZERO_LENGTH])
109+
])
110+
90111

91112
dnl #
92113
dnl # Check if gcc supports -Wno-bool-compare option.

config/kernel.m4

Lines changed: 24 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -2,29 +2,31 @@ dnl #
22
dnl # Default ZFS kernel configuration
33
dnl #
44
AC_DEFUN([ZFS_AC_CONFIG_KERNEL], [
5-
dnl # Setup the kernel build environment.
6-
ZFS_AC_KERNEL
7-
ZFS_AC_QAT
8-
9-
dnl # Sanity checks for module building and CONFIG_* defines
10-
ZFS_AC_KERNEL_TEST_MODULE
11-
ZFS_AC_KERNEL_CONFIG_DEFINED
12-
13-
dnl # Sequential ZFS_LINUX_TRY_COMPILE tests
14-
ZFS_AC_KERNEL_FPU_HEADER
15-
ZFS_AC_KERNEL_WAIT_QUEUE_ENTRY_T
16-
ZFS_AC_KERNEL_MISC_MINOR
17-
ZFS_AC_KERNEL_DECLARE_EVENT_CLASS
18-
19-
dnl # Parallel ZFS_LINUX_TEST_SRC / ZFS_LINUX_TEST_RESULT tests
20-
ZFS_AC_KERNEL_TEST_SRC
21-
ZFS_AC_KERNEL_TEST_RESULT
22-
23-
AS_IF([test "$LINUX_OBJ" != "$LINUX"], [
24-
KERNEL_MAKE="$KERNEL_MAKE O=$LINUX_OBJ"
25-
])
5+
AM_COND_IF([BUILD_LINUX], [
6+
dnl # Setup the kernel build environment.
7+
ZFS_AC_KERNEL
8+
ZFS_AC_QAT
9+
10+
dnl # Sanity checks for module building and CONFIG_* defines
11+
ZFS_AC_KERNEL_TEST_MODULE
12+
ZFS_AC_KERNEL_CONFIG_DEFINED
13+
14+
dnl # Sequential ZFS_LINUX_TRY_COMPILE tests
15+
ZFS_AC_KERNEL_FPU_HEADER
16+
ZFS_AC_KERNEL_WAIT_QUEUE_ENTRY_T
17+
ZFS_AC_KERNEL_MISC_MINOR
18+
ZFS_AC_KERNEL_DECLARE_EVENT_CLASS
19+
20+
dnl # Parallel ZFS_LINUX_TEST_SRC / ZFS_LINUX_TEST_RESULT tests
21+
ZFS_AC_KERNEL_TEST_SRC
22+
ZFS_AC_KERNEL_TEST_RESULT
23+
24+
AS_IF([test "$LINUX_OBJ" != "$LINUX"], [
25+
KERNEL_MAKE="$KERNEL_MAKE O=$LINUX_OBJ"
26+
])
2627
27-
AC_SUBST(KERNEL_MAKE)
28+
AC_SUBST(KERNEL_MAKE)
29+
])
2830
])
2931

3032
dnl #

config/toolchain-simd.m4

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ dnl # Checks if host toolchain supports SIMD instructions
33
dnl #
44
AC_DEFUN([ZFS_AC_CONFIG_ALWAYS_TOOLCHAIN_SIMD], [
55
case "$host_cpu" in
6-
x86_64 | x86 | i686)
6+
amd64 | x86_64 | x86 | i686)
77
ZFS_AC_CONFIG_TOOLCHAIN_CAN_BUILD_SSE
88
ZFS_AC_CONFIG_TOOLCHAIN_CAN_BUILD_SSE2
99
ZFS_AC_CONFIG_TOOLCHAIN_CAN_BUILD_SSE3

config/user.m4

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,25 +4,26 @@ dnl #
44
AC_DEFUN([ZFS_AC_CONFIG_USER], [
55
ZFS_AC_CONFIG_USER_GETTEXT
66
ZFS_AC_CONFIG_USER_MOUNT_HELPER
7-
ZFS_AC_CONFIG_USER_UDEV
8-
ZFS_AC_CONFIG_USER_SYSTEMD
97
ZFS_AC_CONFIG_USER_SYSVINIT
108
ZFS_AC_CONFIG_USER_DRACUT
119
ZFS_AC_CONFIG_USER_ZLIB
12-
ZFS_AC_CONFIG_USER_LIBUUID
10+
AM_COND_IF([BUILD_LINUX], [
11+
ZFS_AC_CONFIG_USER_UDEV
12+
ZFS_AC_CONFIG_USER_SYSTEMD
13+
ZFS_AC_CONFIG_USER_LIBUUID
14+
ZFS_AC_CONFIG_USER_LIBBLKID
15+
])
1316
ZFS_AC_CONFIG_USER_LIBTIRPC
14-
ZFS_AC_CONFIG_USER_LIBBLKID
1517
ZFS_AC_CONFIG_USER_LIBUDEV
1618
ZFS_AC_CONFIG_USER_LIBSSL
1719
ZFS_AC_CONFIG_USER_LIBAIO
1820
ZFS_AC_CONFIG_USER_RUNSTATEDIR
1921
ZFS_AC_CONFIG_USER_MAKEDEV_IN_SYSMACROS
2022
ZFS_AC_CONFIG_USER_MAKEDEV_IN_MKDEV
2123
ZFS_AC_CONFIG_USER_ZFSEXEC
22-
2324
ZFS_AC_TEST_FRAMEWORK
2425
25-
AC_CHECK_FUNCS([mlockall strlcat strlcpy])
26+
AC_CHECK_FUNCS([issetugid mlockall strlcat strlcpy])
2627
])
2728

2829
dnl #

0 commit comments

Comments
 (0)