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

Commit 2cc6d71

Browse files
authored
Expose the libzfs error type (#75)
Expose the libzfs error, so we can use it in other crates. Signed-off-by: Joe Grund <jgrund@whamcloud.io>
1 parent 50af777 commit 2cc6d71

5 files changed

Lines changed: 20 additions & 15 deletions

File tree

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

libzfs/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "libzfs"
3-
version = "0.6.10"
3+
version = "0.6.11"
44
authors = ["IML Team <iml@whamcloud.com>"]
55
description = "Rust wrapper around libzfs-sys"
66
license = "MIT"

libzfs/src/lib.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,11 @@ extern crate lazy_static;
1616

1717
extern crate libzfs_sys as sys;
1818

19-
mod libzfs_error;
2019
mod nvpair;
2120

21+
pub mod libzfs_error;
22+
pub use libzfs_error::*;
23+
2224
pub mod vdev;
2325
pub use vdev::VDev;
2426

libzfs/src/libzfs.rs

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,16 @@
44

55
extern crate libzfs_sys as sys;
66

7-
use std::io::Error;
7+
use libzfs_error::{LibZfsError, Result};
88
use nvpair;
99
use nvpair::ForeignType;
10-
use zpool::Zpool;
11-
use zfs::Zfs;
12-
use std::ptr;
13-
use libzfs_error::{LibZfsError, Result};
1410
use std::ffi::CString;
11+
use std::io::Error;
1512
use std::os::raw::{c_int, c_void};
13+
use std::ptr;
1614
use std::sync::Mutex;
15+
use zfs::Zfs;
16+
use zpool::Zpool;
1717

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

26+
impl Default for Libzfs {
27+
fn default() -> Self {
28+
Libzfs::new()
29+
}
30+
}
31+
2632
impl Libzfs {
2733
pub fn new() -> Libzfs {
2834
Libzfs {
@@ -85,8 +91,7 @@ impl Libzfs {
8591
0 => Ok(()),
8692
x => Err(LibZfsError::Io(Error::from_raw_os_error(x))),
8793
}
88-
})
89-
.collect()
94+
}).collect()
9095
}
9196
pub fn export_all(&mut self, pools: &[Zpool]) -> Result<Vec<()>> {
9297
pools

libzfs/src/vdev.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -100,12 +100,10 @@ pub fn enumerate_vdev_tree(tree: &nvpair::NvList) -> Result<VDev> {
100100

101101
let state = unsafe {
102102
let s = sys::zpool_state_to_name(
103-
sys::to_vdev_state(vdev_stats.vs_state as u32).ok_or(Error::new(
104-
ErrorKind::NotFound,
105-
"vs_state not in enum range",
106-
))?,
103+
sys::to_vdev_state(vdev_stats.vs_state as u32)
104+
.ok_or_else(|| Error::new(ErrorKind::NotFound, "vs_state not in enum range"))?,
107105
sys::to_vdev_aux(vdev_stats.vs_aux as u32)
108-
.ok_or(Error::new(ErrorKind::NotFound, "vs_aux not in enum range"))?,
106+
.ok_or_else(|| Error::new(ErrorKind::NotFound, "vs_aux not in enum range"))?,
109107
);
110108

111109
CStr::from_ptr(s)

0 commit comments

Comments
 (0)