lorenz / go-zfs

GoZFS is a pure-Go implementation of ZFS userspace
MIT License
21 stars 5 forks source link

FreeBSD support #1

Open lapo-luchini opened 2 years ago

lapo-luchini commented 2 years ago

Hi! First of all… sorry if I say strange stuff, but I know nothing about Go language; I'm just trying to build it for testing of zfs_exporter.

% cd ioctl
% go test
go: downloading github.com/stretchr/testify v1.3.0
go: downloading golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a
go: downloading github.com/davecgh/go-spew v1.1.1
# git.dolansoft.org/lorenz/go-zfs/ioctl
../../../go/pkg/mod/github.com/stretchr/testify@v1.3.0/assert/assertions.go:20:2: missing go.sum entry for module providing package github.com/pmezard/go-difflib/difflib (imported by github.com/stretchr/testify/assert); to add:
        go get github.com/stretchr/testify/assert@v1.3.0
FAIL    git.dolansoft.org/lorenz/go-zfs/ioctl [setup failed]
% go build
# git.dolansoft.org/lorenz/go-zfs/ioctl
./wrappers.go:100:32: cannot use int(unix.Mkdev(10, 54)) (type int) as type uint64 in argument to unix.Mknod
% go version
go version go1.17.1 freebsd/amd64
lorenz commented 2 years ago

There is currently no explicit FreeBSD support, it has been developed exclusively against Linux/ZOL. From a quick look the zfs_cmd structure is different on FreeBSD, so this will not work without explicit support (even when fixing the type error). Sadly I have absolutely zero experience with low-level BSD development and no way to test this.

Somebody with more knowledge on how this works on FreeBSD would have to contribute support and a test wrapper (i.e. a FreeBSD kernel running in kvmtool) which I can run in CI to make sure it doesn't regress as I have no other way of testing this.

Also the tests are designed to run in a lightweight Linux VM, running go test standalone is a bit risky for anything else that might be on that system.

lapo-luchini commented 2 years ago

…good to know about go test. Thankfully it didn't work, then!

Linux-only ZOL is no longer, OpenZFS 2.0 is now supporting both Linux and FreeBSD as "tier 1", so I was building it in the hope that it did "just work".

lapo-luchini commented 2 years ago

Other than that… while I would be willing to patch it to work on FreeBSD (as I dislike the lack of zfs details on FreeBSD node_exporter), I have zero Go knowledge and to little time on hands, I fear. I will try some quick hack there and there, maybe. :(

lorenz commented 2 years ago

I know that OpenZFS supports both, but this shares zero code with it as it is implemented in pure Go. You can run this with only the kernel module and not a single ZFS userspace utility or library. And sadly there are differences in the syscall interfaces between FreeBSD and Linux which would need to be accounted for. I'm open to supporting FreeBSD and a large part of what's in this repo (nvlist implementation and function signatures) are probably portable as-is, but somebody who understands how all this low-level stuff works on FreeBSD needs to contribute it.