Skip to content

Commit

Permalink
Add FreeBSD support to ZoL
Browse files Browse the repository at this point in the history
- Import FreeBSD specific parts
- Update tests to work on FreeBSD

Signed-off-by: Matt Macy <mmacy@FreeBSD.org>
Signed-off-by: Ryan Moeller <ryan@ixsystems.com>
  • Loading branch information
kmoore134 authored and mattmacy committed Dec 13, 2019
1 parent c317c8c commit aa23d2c
Show file tree
Hide file tree
Showing 375 changed files with 87,455 additions and 406 deletions.
24 changes: 24 additions & 0 deletions .gitignore
Expand Up @@ -63,3 +63,27 @@ cscope.*
*.orig
*.log
venv

*.so
*.so.debug
*.so.full
*.tmp
*.log

#
# Module leftovers
#
/module/avl/zavl.mod
/module/icp/icp.mod
/module/lua/zlua.mod
/module/nvpair/znvpair.mod
/module/spl/spl.mod
/module/unicode/zunicode.mod
/module/zcommon/zcommon.mod
/module/zfs/zfs.mod

module/export_syms
module/machine
module/x86
module/zfs.ko.debug
module/zfs.ko.full
1 change: 1 addition & 0 deletions Makefile.am
Expand Up @@ -106,6 +106,7 @@ commitcheck:
cstyle:
@find ${top_srcdir} -name build -prune -o -name '*.[hc]' \
! -name 'zfs_config.*' ! -name '*.mod.c' -type f \
! -name '*_if*.h' ! -path "*/os/freebsd/*" \
-exec ${top_srcdir}/scripts/cstyle.pl -cpP {} \+

filter_executable = -exec test -x '{}' \; -print
Expand Down
87 changes: 73 additions & 14 deletions README.md
@@ -1,31 +1,90 @@
![img](http://zfsonlinux.org/images/zfs-linux.png)
![img](https://github.com/zfsonfreebsd/ZoF/raw/master/zof-logo.png)

ZFS on Linux is an advanced file system and volume manager which was originally
developed for Solaris and is now maintained by the OpenZFS community.
developed for Solaris and is now maintained by the OpenZFS community. ZoF is
the work to bring FreeBSD support into the ZoL repo.

[![codecov](https://codecov.io/gh/zfsonlinux/zfs/branch/master/graph/badge.svg)](https://codecov.io/gh/zfsonlinux/zfs)
[![coverity](https://scan.coverity.com/projects/1973/badge.svg)](https://scan.coverity.com/projects/zfsonlinux-zfs)

# Official Resources

* [Site](http://zfsonlinux.org)
* [Wiki](https://github.com/zfsonlinux/zfs/wiki)
* [Mailing lists](https://github.com/zfsonlinux/zfs/wiki/Mailing-Lists)
* [ZoF GitHub Site](https://zfsonfreebsd.github.io/ZoF/)
* [ZoL Site](http://zfsonlinux.org)
* [ZoL Wiki](https://github.com/zfsonlinux/zfs/wiki)
* [ZoL Mailing lists](https://github.com/zfsonlinux/zfs/wiki/Mailing-Lists)
* [OpenZFS site](http://open-zfs.org/)

# Installation

Full documentation for installing ZoL on your favorite Linux distribution can
be found at [our site](http://zfsonlinux.org/).
ZoF is available in the FreeBSD ports tree as sysutils/openzfs and
sysutils/openzfs-kmod. It can be installed on FreeBSD stable/12 or later.

# Contribute & Develop
# Branches

We have a separate document with [contribution guidelines](./.github/CONTRIBUTING.md).
* projects/zfsbsd - stable branch used by the port
* projects/pr-rebase-* - development branch, frequently rebased on ZoL master
* projects/pr-rebase - squashed development branch for the ZoL PR

# Release
We frequently rebase the development branch on ZoL master to keep up with
upstream changes, creating a new branch to preserve the commit history in case
of mismerges and to avoid force pushes.

ZFS on Linux is released under a CDDL license.
For more details see the NOTICE, LICENSE and COPYRIGHT files; `UCRL-CODE-235197`
# Development

The following dependencies are required to build ZoF from source:
* FreeBSD sources (in /usr/src or elsewhere specified by passing
`--with-freebsd=$path` to `./configure`
* Packages for build:
```
autoconf
automake
autotools
bash
git
gmake
```
* Optional packages for build:
```
python3 # or your preferred Python version
```
* Optional packages for test:
```
base64
fio
hs-ShellCheck
ksh93
py36-flake8 # or your preferred Python version
shuf
sudo
```
The user for running tests must have NOPASSWD sudo permission.

To build and install:
```
# as user
git clone https://github.com/zfsonfreebsd/ZoF
cd ZoF
./autogen.sh
./configure
gmake
# as root
gmake install
```
The ZFS utilities will be installed in /usr/local/sbin/, so make sure your PATH
gets adjusted accordingly. Though not required, `WITHOUT_ZFS` is a useful build
option to avoid installing legacy zfs tools and kmod - see `src.conf(5)`.

Beware that the FreeBSD boot loader does not allow booting from root pools with
encryption active (even if it is not in use), so do not try encryption on a
pool you boot from.

# Contributing

Submit changes to the common code via a ZoL PR. Submit changes to FreeBSD
platform code by way of a PR to ZoF against the latest development branch.

# Issues

Issues can be reported via GitHub's [Issue Tracker](https://github.com/zfsonfreebsd/ZoF).

# Supported Kernels
* The `META` file contains the officially recognized supported kernel versions.
1 change: 1 addition & 0 deletions _config.yml
@@ -0,0 +1 @@
theme: jekyll-theme-slate
8 changes: 8 additions & 0 deletions cmd/zpool/Makefile.am
Expand Up @@ -11,6 +11,10 @@ zpool_SOURCES = \
zpool_util.h \
zpool_vdev.c

if BUILD_FREEBSD
zpool_SOURCES += os/freebsd/zpool_vdev_os.c
endif

if BUILD_LINUX
zpool_SOURCES += os/linux/zpool_vdev_os.c
endif
Expand All @@ -20,6 +24,10 @@ zpool_LDADD = \
$(top_builddir)/lib/libuutil/libuutil.la \
$(top_builddir)/lib/libzfs/libzfs.la

# XXX
if BUILD_FREEBSD
zpool_LDADD += -L/usr/local/lib -lintl -lgeom
endif
zpool_LDADD += -lm $(LIBBLKID)

zpoolconfdir = $(sysconfdir)/zfs/zpool.d
Expand Down
136 changes: 136 additions & 0 deletions cmd/zpool/os/freebsd/zpool_vdev_os.c
@@ -0,0 +1,136 @@
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "License").
* You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* or http://www.opensolaris.org/os/licensing.
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/

/*
* Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2013, 2018 by Delphix. All rights reserved.
* Copyright (c) 2016, 2017 Intel Corporation.
* Copyright 2016 Igor Kozhukhov <ikozhukhov@gmail.com>.
*/

/*
* Functions to convert between a list of vdevs and an nvlist representing the
* configuration. Each entry in the list can be one of:
*
* Device vdevs
* disk=(path=..., devid=...)
* file=(path=...)
*
* Group vdevs
* raidz[1|2]=(...)
* mirror=(...)
*
* Hot spares
*
* While the underlying implementation supports it, group vdevs cannot contain
* other group vdevs. All userland verification of devices is contained within
* this file. If successful, the nvlist returned can be passed directly to the
* kernel; we've done as much verification as possible in userland.
*
* Hot spares are a special case, and passed down as an array of disk vdevs, at
* the same level as the root of the vdev tree.
*
* The only function exported by this file is 'make_root_vdev'. The
* function performs several passes:
*
* 1. Construct the vdev specification. Performs syntax validation and
* makes sure each device is valid.
* 2. Check for devices in use. Using libdiskmgt, makes sure that no
* devices are also in use. Some can be overridden using the 'force'
* flag, others cannot.
* 3. Check for replication errors if the 'force' flag is not specified.
* validates that the replication level is consistent across the
* entire pool.
* 4. Call libzfs to label any whole disks with an EFI label.
*/

#include <assert.h>
#include <errno.h>
#include <fcntl.h>
#include <libintl.h>
#include <libnvpair.h>
#include <libzutil.h>
#include <limits.h>
#include <sys/spa.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <paths.h>
#include <sys/stat.h>
#include <sys/disk.h>
#include <sys/mntent.h>
#include <libgeom.h>

#include "zpool_util.h"
#include <sys/zfs_context.h>

int
check_device(const char *name, boolean_t force, boolean_t isspare,
boolean_t iswholedisk)
{
char path[MAXPATHLEN];

if (strncmp(name, _PATH_DEV, sizeof (_PATH_DEV) - 1) != 0)
snprintf(path, sizeof (path), "%s%s", _PATH_DEV, name);
else
strlcpy(path, name, sizeof (path));

return (check_file(path, force, isspare));
}

#ifdef notyet
/*
* By "whole disk" we mean an entire physical disk (something we can
* label, toggle the write cache on, etc.) as opposed to the full
* capacity of a pseudo-device such as lofi or did. We act as if we
* are labeling the disk, which should be a pretty good test of whether
* it's a viable device or not. Returns B_TRUE if it is and B_FALSE if
* it isn't.
*/
static boolean_t
is_whole_disk(const char *arg)
{
int fd;

fd = g_open(arg, 0);
if (fd >= 0) {
g_close(fd);
return (B_TRUE);
}
return (B_FALSE);
}
#endif

boolean_t
check_sector_size_database(char *path, int *sector_size)
{
return (0);
}

void
zpool_vdev_enable_file(struct stat64 *statbuf, boolean_t *wholedisk)
{
if (S_ISCHR(statbuf->st_mode)) {
statbuf->st_mode &= ~S_IFCHR;
statbuf->st_mode |= S_IFBLK;
*wholedisk = B_FALSE;
}
}
31 changes: 29 additions & 2 deletions config/Rules.am
Expand Up @@ -14,26 +14,53 @@ DEFAULT_INCLUDES += \
-I$(top_srcdir)/lib/libspl/include/os/linux
endif

if BUILD_FREEBSD
DEFAULT_INCLUDES += \
-I$(top_srcdir)/lib/libspl/include/os/freebsd
endif

if BUILD_LINUX
AM_LIBTOOLFLAGS = --silent
endif

AM_CFLAGS = -std=gnu99 -Wall -Wstrict-prototypes -fno-strict-aliasing
AM_CFLAGS += $(NO_OMIT_FRAME_POINTER)
AM_CFLAGS += $(DEBUG_CFLAGS)
AM_CFLAGS += $(ASAN_CFLAGS)
AM_CFLAGS += $(CODE_COVERAGE_CFLAGS)
AM_CFLAGS += $(CODE_COVERAGE_CFLAGS) $(NO_FORMAT_ZERO_LENGTH)
if BUILD_FREEBSD
AM_CFLAGS += -fPIC -Werror -Wno-unknown-pragmas -Wno-enum-conversion
AM_CFLAGS += -include $(top_srcdir)/include/os/freebsd/spl/sys/ccompile.h
AM_CFLAGS += -I/usr/include -I/usr/local/include
AM_CFLAGS += -D_MACHINE_ENDIAN_H_
endif

AM_CPPFLAGS = -D_GNU_SOURCE
AM_CPPFLAGS += -D_REENTRANT
AM_CPPFLAGS += -D_FILE_OFFSET_BITS=64
AM_CPPFLAGS += -D_LARGEFILE64_SOURCE
AM_CPPFLAGS += -DHAVE_LARGE_STACKS=1
AM_CPPFLAGS += -DTEXT_DOMAIN=\"zfs-linux-user\"
AM_CPPFLAGS += -DLIBEXECDIR=\"$(libexecdir)\"
AM_CPPFLAGS += -DRUNSTATEDIR=\"$(runstatedir)\"
AM_CPPFLAGS += -DSBINDIR=\"$(sbindir)\"
AM_CPPFLAGS += -DSYSCONFDIR=\"$(sysconfdir)\"
AM_CPPFLAGS += $(DEBUG_CPPFLAGS)
AM_CPPFLAGS += $(CODE_COVERAGE_CPPFLAGS)
if BUILD_LINUX
AM_CPPFLAGS += -DTEXT_DOMAIN=\"zfs-linux-user\"
endif
if BUILD_FREEBSD
AM_CPPFLAGS += -DTEXT_DOMAIN=\"zfs-freebsd-user\"
# FIXME: are the rest of these needed?
AM_CPPFLAGS += -D_SYS_VMEM_H_ -D_SYS_PROC_H_ -DVM_H -D_SYS_USER_H_
AM_CPPFLAGS += -DZFS_DEBUG
endif

AM_LDFLAGS = $(DEBUG_LDFLAGS)
AM_LDFLAGS += $(ASAN_LDFLAGS)

if BUILD_FREEBSD
AM_LDFLAGS += -fstack-protector-strong -shared
AM_LDFLAGS += -Wl,-x -Wl,--fatal-warnings -Wl,--warn-shared-textrel
AM_LDFLAGS += -lm
endif
3 changes: 2 additions & 1 deletion config/always-arch.m4
Expand Up @@ -3,7 +3,8 @@ dnl # Set the target arch for libspl atomic implementation and the icp
dnl #
AC_DEFUN([ZFS_AC_CONFIG_ALWAYS_ARCH], [
AC_MSG_CHECKING(for target asm dir)
TARGET_ARCH=`echo ${target_cpu} | sed -e s/i.86/i386/`
subs="-e s/i.86/i386/ -e s/amd64/x86_64/"
TARGET_ARCH=$(echo ${target_cpu} | sed ${subs})
case $TARGET_ARCH in
i386|x86_64)
Expand Down

0 comments on commit aa23d2c

Please sign in to comment.