src/tools/disks/zfs.rs: cleanup (rename usage properties)
And allow to parse zpool list output without -v flag.
This commit is contained in:
parent
3378fd9fe5
commit
36c65ee0b0
@ -29,19 +29,19 @@ type IResult<I, O, E = VerboseError<I>> = Result<(I, O), nom::Err<E>>;
|
|||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct ZFSPoolUsage {
|
pub struct ZFSPoolUsage {
|
||||||
total: u64,
|
pub size: u64,
|
||||||
used: u64,
|
pub alloc: u64,
|
||||||
free: u64,
|
pub free: u64,
|
||||||
dedup: f64,
|
pub dedup: f64,
|
||||||
fragmentation: u64,
|
pub frag: u64,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct ZFSPoolStatus {
|
pub struct ZFSPoolStatus {
|
||||||
name: String,
|
pub name: String,
|
||||||
health: String,
|
pub health: String,
|
||||||
usage: Option<ZFSPoolUsage>,
|
pub usage: Option<ZFSPoolUsage>,
|
||||||
devices: Vec<String>,
|
pub devices: Vec<String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns kernel IO-stats for zfs pools
|
/// Returns kernel IO-stats for zfs pools
|
||||||
@ -130,8 +130,8 @@ fn parse_pool_device(i: &str) -> IResult<&str, String> {
|
|||||||
fn parse_pool_header(i: &str) -> IResult<&str, ZFSPoolStatus> {
|
fn parse_pool_header(i: &str) -> IResult<&str, ZFSPoolStatus> {
|
||||||
// name, size, allocated, free, checkpoint, expandsize, fragmentation, capacity, dedupratio, health, altroot.
|
// name, size, allocated, free, checkpoint, expandsize, fragmentation, capacity, dedupratio, health, altroot.
|
||||||
|
|
||||||
let (i, (text, total, used, free, _, _,
|
let (i, (text, size, alloc, free, _, _,
|
||||||
fragmentation, _, dedup, health,
|
frag, _, dedup, health,
|
||||||
_, _eol)) = tuple((
|
_, _eol)) = tuple((
|
||||||
take_while1(|c| char::is_alphanumeric(c)), // name
|
take_while1(|c| char::is_alphanumeric(c)), // name
|
||||||
preceded(multispace1, parse_optional_u64), // size
|
preceded(multispace1, parse_optional_u64), // size
|
||||||
@ -147,11 +147,11 @@ fn parse_pool_header(i: &str) -> IResult<&str, ZFSPoolStatus> {
|
|||||||
line_ending,
|
line_ending,
|
||||||
))(i)?;
|
))(i)?;
|
||||||
|
|
||||||
let status = if let (Some(total), Some(used), Some(free), Some(fragmentation), Some(dedup)) = (total, used, free, fragmentation, dedup) {
|
let status = if let (Some(size), Some(alloc), Some(free), Some(frag), Some(dedup)) = (size, alloc, free, frag, dedup) {
|
||||||
ZFSPoolStatus {
|
ZFSPoolStatus {
|
||||||
name: text.into(),
|
name: text.into(),
|
||||||
health: health.into(),
|
health: health.into(),
|
||||||
usage: Some(ZFSPoolUsage { total, used, free, fragmentation, dedup }),
|
usage: Some(ZFSPoolUsage { size, alloc, free, frag, dedup }),
|
||||||
devices: Vec::new(),
|
devices: Vec::new(),
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@ -169,7 +169,7 @@ fn parse_pool_header(i: &str) -> IResult<&str, ZFSPoolStatus> {
|
|||||||
fn parse_pool_status(i: &str) -> IResult<&str, ZFSPoolStatus> {
|
fn parse_pool_status(i: &str) -> IResult<&str, ZFSPoolStatus> {
|
||||||
|
|
||||||
let (i, mut stat) = parse_pool_header(i)?;
|
let (i, mut stat) = parse_pool_header(i)?;
|
||||||
let (i, devices) = many1(parse_pool_device)(i)?;
|
let (i, devices) = many0(parse_pool_device)(i)?;
|
||||||
|
|
||||||
for device_path in devices.into_iter().filter(|n| n.starts_with("/dev/")) {
|
for device_path in devices.into_iter().filter(|n| n.starts_with("/dev/")) {
|
||||||
stat.devices.push(device_path);
|
stat.devices.push(device_path);
|
||||||
|
Loading…
Reference in New Issue
Block a user