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

Commit

Permalink
Add libzfs types (#77)
Browse files Browse the repository at this point in the history
* Move shared types into their own crate.

Currently, taking a dep on libzfs means your crate gets linked against
libzfs.so.2 libzpool.so.2 and libnvpair.so.2. Take device-aggregator for
instance, which only takes a dep on libzfs to get shared types:

```shell
$ ldd /usr/bin/device-aggregator
	linux-vdso.so.1 =>  (0x00007ffdba5b8000)
	libzfs.so.2 => not found
	libzpool.so.2 => not found
	libnvpair.so.1 => not found
	libdl.so.2 => /lib64/libdl.so.2 (0x00007f49332af000)
	librt.so.1 => /lib64/librt.so.1 (0x00007f49330a7000)
	libpthread.so.0 => /lib64/libpthread.so.0 (0x00007f4932e8b000)
	libgcc_s.so.1 => /lib64/libgcc_s.so.1 (0x00007f4932c75000)
	libc.so.6 => /lib64/libc.so.6 (0x00007f49328a8000)
	/lib64/ld-linux-x86-64.so.2 (0x00007f4933905000)
	libm.so.6 => /lib64/libm.so.6 (0x00007f49325a6000)
```

We don't need libzfs to be linked in crates that only need type access.
Instead, extract types to their own standalone crate that doesn't have a
dep on libzfs-sys. This way we can get type access without linking to
unneeded shared objects.

Signed-off-by: Joe Grund <[email protected]>

* Move shared types into their own crate.

Currently, taking a dep on libzfs means your crate gets linked against
libzfs.so.2 libzpool.so.2 and libnvpair.so.2. Take device-aggregator for
instance, which only takes a dep on libzfs to get shared types:

```shell
$ ldd /usr/bin/device-aggregator
	linux-vdso.so.1 =>  (0x00007ffdba5b8000)
	libzfs.so.2 => not found
	libzpool.so.2 => not found
	libnvpair.so.1 => not found
	libdl.so.2 => /lib64/libdl.so.2 (0x00007f49332af000)
	librt.so.1 => /lib64/librt.so.1 (0x00007f49330a7000)
	libpthread.so.0 => /lib64/libpthread.so.0 (0x00007f4932e8b000)
	libgcc_s.so.1 => /lib64/libgcc_s.so.1 (0x00007f4932c75000)
	libc.so.6 => /lib64/libc.so.6 (0x00007f49328a8000)
	/lib64/ld-linux-x86-64.so.2 (0x00007f4933905000)
	libm.so.6 => /lib64/libm.so.6 (0x00007f49325a6000)
```

We don't need libzfs to be linked in crates that only need type access.
Instead, extract types to their own standalone crate that doesn't have a
dep on libzfs-sys. This way we can get type access without linking to
unneeded shared objects.

Signed-off-by: Joe Grund <[email protected]>
  • Loading branch information
jgrund authored Nov 8, 2018
1 parent 8454ea1 commit 9f7eb03
Show file tree
Hide file tree
Showing 13 changed files with 153 additions and 106 deletions.
7 changes: 7 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@ jobs:
script:
- docker run -d -it --name libzfs -v $(pwd):/rust-libzfs:rw imlteam/zfs
- docker exec -i libzfs bash -c "cd /rust-libzfs/libzfs && cargo package && cargo publish --token $CARGO_TOKEN"
- stage: deploy-libzfs-types
name: "libzfs-types"
script:
- docker run -d -it --name libzfs -v $(pwd):/rust-libzfs:rw imlteam/zfs
- docker exec -i libzfs bash -c "cd /rust-libzfs/libzfs-types && cargo package && cargo publish --token $CARGO_TOKEN"
- stage: deploy-node-libzfs
name: "@iml/node-libzfs"
language: node_js
Expand Down Expand Up @@ -56,6 +61,8 @@ stages:
if: branch =~ ^v\d+\.\d+\.\d+libzfs-sys$
- name: deploy-libzfs
if: branch =~ ^v\d+\.\d+\.\d+libzfs$
- name: deploy-libzfs-types
if: branch =~ ^v\d+\.\d+\.\d+libzfs-types$
- name: deploy-node-libzfs
if: branch =~ ^v\d+\.\d+\.\d+node-libzfs$
- name: deploy-copr
Expand Down
48 changes: 27 additions & 21 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
[workspace]
members = ['libzfs-sys', 'libzfs']
exclude = ['node-libzfs']
members = ['libzfs-sys', 'libzfs', 'libzfs-types']
exclude = ['node-libzfs']
2 changes: 1 addition & 1 deletion libzfs-sys/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,5 @@ build = "build.rs"
nvpair-sys = "0.1"

[build-dependencies]
bindgen = "0.43.0"
bindgen = "0.43.1"
pkg-config = "0.3.14"
5 changes: 4 additions & 1 deletion libzfs-sys/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@ fn main() {

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

pkg_config::Config::new().probe("libzfs").unwrap();
pkg_config::Config::new()
.atleast_version("0.7.9")
.probe("libzfs")
.unwrap();
println!("cargo:rustc-link-lib=zpool");

// Skip building if bindings already exist.
Expand Down
10 changes: 10 additions & 0 deletions libzfs-types/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[package]
name = "libzfs-types"
version = "0.1.0"
authors = ["IML Team <[email protected]>"]
description = "Shared types for libzfs"
license = "MIT"

[dependencies]
serde = "1.0"
serde_derive = "1.0"
76 changes: 76 additions & 0 deletions libzfs-types/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
// Copyright (c) 2018 DDN. All rights reserved.
// Use of this source code is governed by a MIT-style
// license that can be found in the LICENSE file.

//! libzfs-types — Shared types for libzfs
//!

extern crate serde_derive;

use serde_derive::{Deserialize, Serialize};
use std::path::PathBuf;

#[derive(Debug, PartialEq, Eq, Hash, Serialize, Deserialize, Clone)]
pub enum VDev {
Mirror {
children: Vec<VDev>,
is_log: Option<bool>,
},
RaidZ {
children: Vec<VDev>,
},
Replacing {
children: Vec<VDev>,
},
Root {
children: Vec<VDev>,
spares: Vec<VDev>,
cache: Vec<VDev>,
},
Disk {
guid: Option<u64>,
state: String,
path: PathBuf,
dev_id: Option<String>,
phys_path: Option<String>,
whole_disk: Option<bool>,
is_log: Option<bool>,
},
File {
guid: Option<u64>,
state: String,
path: PathBuf,
is_log: Option<bool>,
},
}

#[derive(Debug, PartialEq, Eq, Hash, Deserialize, Serialize, Clone)]
pub struct ZProp {
pub name: String,
pub value: String,
}

/// A Pool at a point in time
#[derive(Debug, Serialize, Deserialize, Clone)]
pub struct Pool {
pub name: String,
pub guid: u64,
pub health: String,
pub hostname: String,
pub hostid: Option<u64>,
pub state: String,
pub readonly: bool,
pub size: String,
pub vdev: VDev,
pub props: Vec<ZProp>,
pub datasets: Vec<Dataset>,
}

/// A Dataset at a point in time
#[derive(Debug, Serialize, Deserialize, Clone)]
pub struct Dataset {
pub name: String,
pub guid: String,
pub kind: String,
pub props: Vec<ZProp>,
}
3 changes: 2 additions & 1 deletion libzfs/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ description = "Rust wrapper around libzfs-sys"
license = "MIT"

[dependencies]
libzfs-sys = { path = "../libzfs-sys", version = "0.5.7" }
libzfs-sys = { path = "../libzfs-sys", version = "0.5.7"}
libzfs-types = { path = "../libzfs-types", version = "0.1.0" }
nvpair-sys = "0.1"
serde = "1.0"
serde_derive = "1.0"
Expand Down
3 changes: 2 additions & 1 deletion libzfs/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
//! libzfs — Rusty wrapper around libzfs-sys.
//!

#[macro_use]
extern crate serde_derive;

#[macro_use]
Expand All @@ -16,6 +15,8 @@ extern crate lazy_static;

extern crate libzfs_sys as sys;

extern crate libzfs_types;

mod nvpair;

pub mod libzfs_error;
Expand Down
28 changes: 1 addition & 27 deletions libzfs/src/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,35 +12,9 @@ use std::io;

use libzfs::Libzfs;
use libzfs_error::{LibZfsError, Result};
use vdev::VDev;
use libzfs_types::{Dataset, Pool};
use zfs::Zfs;
use zpool::Zpool;
use zprop_list::ZProp;

/// A Pool at a point in time
#[derive(Debug, Serialize, Deserialize, Clone)]
pub struct Pool {
pub name: String,
pub guid: u64,
pub health: String,
pub hostname: String,
pub hostid: Option<u64>,
pub state: String,
pub readonly: bool,
pub size: String,
pub vdev: VDev,
pub props: Vec<ZProp>,
pub datasets: Vec<Dataset>,
}

/// A Dataset at a point in time
#[derive(Debug, Serialize, Deserialize, Clone)]
pub struct Dataset {
pub name: String,
pub guid: String,
pub kind: String,
pub props: Vec<ZProp>,
}

/// Takes a Zfs reference and converts it into a
/// `Dataset`
Expand Down
Loading

0 comments on commit 9f7eb03

Please sign in to comment.