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

Commit

Permalink
Expose the libzfs error type (#75)
Browse files Browse the repository at this point in the history
Expose the libzfs error, so we can use it in other crates.

Signed-off-by: Joe Grund <[email protected]>
  • Loading branch information
jgrund authored Nov 2, 2018
1 parent 50af777 commit 2cc6d71
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 15 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

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

2 changes: 1 addition & 1 deletion libzfs/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "libzfs"
version = "0.6.10"
version = "0.6.11"
authors = ["IML Team <[email protected]>"]
description = "Rust wrapper around libzfs-sys"
license = "MIT"
Expand Down
4 changes: 3 additions & 1 deletion libzfs/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,11 @@ extern crate lazy_static;

extern crate libzfs_sys as sys;

mod libzfs_error;
mod nvpair;

pub mod libzfs_error;
pub use libzfs_error::*;

pub mod vdev;
pub use vdev::VDev;

Expand Down
19 changes: 12 additions & 7 deletions libzfs/src/libzfs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,16 @@

extern crate libzfs_sys as sys;

use std::io::Error;
use libzfs_error::{LibZfsError, Result};
use nvpair;
use nvpair::ForeignType;
use zpool::Zpool;
use zfs::Zfs;
use std::ptr;
use libzfs_error::{LibZfsError, Result};
use std::ffi::CString;
use std::io::Error;
use std::os::raw::{c_int, c_void};
use std::ptr;
use std::sync::Mutex;
use zfs::Zfs;
use zpool::Zpool;

lazy_static! {
pub static ref LOCK: Mutex<()> = Mutex::new(());
Expand All @@ -23,6 +23,12 @@ pub struct Libzfs {
raw: *mut sys::libzfs_handle_t,
}

impl Default for Libzfs {
fn default() -> Self {
Libzfs::new()
}
}

impl Libzfs {
pub fn new() -> Libzfs {
Libzfs {
Expand Down Expand Up @@ -85,8 +91,7 @@ impl Libzfs {
0 => Ok(()),
x => Err(LibZfsError::Io(Error::from_raw_os_error(x))),
}
})
.collect()
}).collect()
}
pub fn export_all(&mut self, pools: &[Zpool]) -> Result<Vec<()>> {
pools
Expand Down
8 changes: 3 additions & 5 deletions libzfs/src/vdev.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,12 +100,10 @@ pub fn enumerate_vdev_tree(tree: &nvpair::NvList) -> Result<VDev> {

let state = unsafe {
let s = sys::zpool_state_to_name(
sys::to_vdev_state(vdev_stats.vs_state as u32).ok_or(Error::new(
ErrorKind::NotFound,
"vs_state not in enum range",
))?,
sys::to_vdev_state(vdev_stats.vs_state as u32)
.ok_or_else(|| Error::new(ErrorKind::NotFound, "vs_state not in enum range"))?,
sys::to_vdev_aux(vdev_stats.vs_aux as u32)
.ok_or(Error::new(ErrorKind::NotFound, "vs_aux not in enum range"))?,
.ok_or_else(|| Error::new(ErrorKind::NotFound, "vs_aux not in enum range"))?,
);

CStr::from_ptr(s)
Expand Down

0 comments on commit 2cc6d71

Please sign in to comment.