Skip to content
This repository has been archived by the owner on Jul 25, 2024. It is now read-only.

ZoL master and FreeBSD 11.2 support #64

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 52 additions & 13 deletions libzfs-sys/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,19 @@ extern crate bindgen;
extern crate pkg_config;

use std::env;
use std::io::{BufRead, BufReader};
use std::path::PathBuf;
use std::process::{Command, Stdio};

fn main() {
let out_file = env::current_dir().unwrap().join("src").join("bindings.rs");

env::set_var("LIBCLANG_PATH", "/opt/llvm-5.0.0/lib64/");

pkg_config::Config::new().probe("libzfs").unwrap();
println!("cargo:rustc-link-lib=zpool");
// necessary for CI machines to find their libclang install
env::set_var("LIBCLANG_PATH", "/opt/llvm-5.0.0/lib64");

let bindings = bindgen::Builder::default()
.header("wrapper.h")
.constified_enum_module("boolean")
.constified_enum_module("boolean_t")
.whitelist_var("vdev_stat_t")
.whitelist_type("vdev_stat_t")
.whitelist_var("ZPOOL_MAXPROPLEN")
Expand Down Expand Up @@ -61,8 +62,6 @@ fn main() {
.blacklist_type("nvlist")
.whitelist_function("libzfs_init")
.whitelist_function("libzfs_fini")
.whitelist_function("thread_init")
.whitelist_function("thread_fini")
.whitelist_function("zpool_import")
.whitelist_function("zpool_export")
.whitelist_function("zpool_find_import")
Expand Down Expand Up @@ -91,15 +90,55 @@ fn main() {
.whitelist_function("zfs_expand_proplist")
.whitelist_function("zfs_prop_to_name")
.whitelist_function("zfs_validate_name")
.whitelist_function("zprop_free_list")
.clang_arg("-I/usr/lib/gcc/x86_64-redhat-linux/4.8.2/include/")
.clang_arg("-I/usr/src/zfs-0.7.9/lib/libspl/include/")
.clang_arg("-I/usr/src/zfs-0.7.9/include/")
.generate()
.expect("Unable to generate bindings");
.whitelist_function("zprop_free_list");

let bindings = if cfg!(target_os = "freebsd") {
println!("cargo:rustc-link-lib=zfs");
// a subset of include paths in cddl/sbin/zfs/Makefile
bindings
.clang_arg("-I/usr/src/cddl/compat/opensolaris/include")
.clang_arg("-I/usr/src/cddl/compat/opensolaris/lib/libumem")
.clang_arg("-I/usr/src/cddl/contrib/opensolaris/head")
.clang_arg("-I/usr/src/cddl/contrib/opensolaris/lib/libuutil/common")
.clang_arg("-I/usr/src/cddl/contrib/opensolaris/lib/libzfs/common")
.clang_arg("-I/usr/src/cddl/contrib/opensolaris/lib/libzpool/common")
.clang_arg("-I/usr/src/sys/cddl/compat/opensolaris")
.clang_arg("-I/usr/src/sys/cddl/contrib/opensolaris/uts/common")
.clang_arg("-I/usr/src/sys/cddl/contrib/opensolaris/uts/common/fs/zfs")
.clang_arg("-I/usr/src/sys/cddl/contrib/opensolaris/common/zfs")
} else {
let libzfs = pkg_config::Config::new().probe("libzfs").unwrap();
list_gcc_include_paths()
.chain(libzfs.include_paths)
.fold(bindings, |bindings, include_path| {
let flag = format!("-I{}", include_path.to_string_lossy());
bindings.clang_arg(flag)
})
// include directory for zfsonlinux/zfs master branch
.clang_arg("-I/usr/src/zfs-0.7.0/include")
Copy link
Member

@jgrund jgrund Jul 16, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will get a bit farther if it is changed to:

.clang_arg("-I/usr/src/zfs-0.7.9/include")

};

let bindings = bindings.generate().expect("Unable to generate bindings");

println!("cargo:rustc-link-lib=zpool");

// Write bindings to src.
bindings
.write_to_file(out_file)
.expect("Couldn't write bindings!");
}

fn list_gcc_include_paths() -> impl Iterator<Item = PathBuf> {
let script_path = "./list_gcc_include_paths.sh";
let child = Command::new(script_path)
.stdout(Stdio::piped())
.spawn()
.expect(&format!("Unable to spawn {}", script_path));

match child.stdout {
Some(stdout) =>
BufReader::new(stdout).lines()
.map(|line| PathBuf::from(line.unwrap())),
None => panic!("Couldn't read from {}", script_path),
}
}
3 changes: 3 additions & 0 deletions libzfs-sys/list_gcc_include_paths.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/sh

gcc -Wp,-v -x c - -fsyntax-only < /dev/null 2>&1 | grep '^ ' | sed -e 's/^ //'
2 changes: 2 additions & 0 deletions libzfs-sys/wrapper.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,6 @@

#define _LARGEFILE64_SOURCE

#define NEED_SOLARIS_BOOLEAN

#include <libzfs_impl.h>
2 changes: 0 additions & 2 deletions libzfs/src/libzfs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,7 @@ impl Libzfs {
pub fn find_importable_pools(&mut self) -> nvpair::NvList {
let _l = LOCK.lock().unwrap();
unsafe {
sys::thread_init();
let x = sys::zpool_find_import(self.raw, 0, ptr::null_mut());
sys::thread_fini();

nvpair::NvList::from_ptr(x)
}
Expand Down
8 changes: 4 additions & 4 deletions libzfs/src/zfs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ impl Zfs {
sys::zfs_expand_proplist(
self.raw,
&mut prop_list_ptr,
sys::boolean::B_TRUE,
sys::boolean::B_TRUE,
sys::boolean_t::B_TRUE,
sys::boolean_t::B_TRUE,
)
};

Expand All @@ -62,7 +62,7 @@ impl Zfs {
let pl = self.prop_list()?;

let xs = pl.filter_map(|x: ZpropItem| match x.prop() {
sys::zfs_prop_t_ZFS_PROP_BAD => self.user_props()
sys::zfs_prop_t_ZPROP_INVAL => self.user_props()
.lookup_nv_list(x.user_prop())
.and_then(|nv| nv.lookup_string(sys::zprop_value()))
.map(|v| ZProp {
Expand All @@ -82,7 +82,7 @@ impl Zfs {
ptr::null_mut(),
ptr::null_mut(),
0,
sys::boolean::B_TRUE,
sys::boolean_t::B_TRUE,
)
};

Expand Down
6 changes: 3 additions & 3 deletions libzfs/src/zpool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ impl Zpool {
raw,
sys::ZPOOL_MAXPROPLEN as usize,
ptr::null_mut(),
sys::boolean::B_FALSE,
sys::boolean_t::B_FALSE,
);

let out = CString::from_raw(raw);
Expand Down Expand Up @@ -141,15 +141,15 @@ impl Zpool {
}
}
pub fn disable_datasets(&self) -> Result<()> {
let code = unsafe { sys::zpool_disable_datasets(self.raw, sys::boolean::B_FALSE) };
let code = unsafe { sys::zpool_disable_datasets(self.raw, sys::boolean_t::B_FALSE) };

match code {
0 => Ok(()),
e => Err(LibZfsError::Io(Error::from_raw_os_error(e))),
}
}
pub fn export(&self) -> Result<()> {
let code = unsafe { sys::zpool_export(self.raw, sys::boolean::B_FALSE, ptr::null_mut()) };
let code = unsafe { sys::zpool_export(self.raw, sys::boolean_t::B_FALSE, ptr::null_mut()) };

match code {
0 => Ok(()),
Expand Down