Skip to content

Commit

Permalink
Use strum macros for ThinPoolStatusDigest strings
Browse files Browse the repository at this point in the history
Signed-off-by: mulhern <amulhern@redhat.com>
  • Loading branch information
mulkieran committed Mar 28, 2024
1 parent ae9469b commit 1f95306
Showing 1 changed file with 17 additions and 23 deletions.
40 changes: 17 additions & 23 deletions src/engine/strat_engine/thinpool/thinpool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
use std::{
cmp::{max, min, Ordering},
collections::{HashMap, HashSet},
fmt,
thread::scope,
};

Expand Down Expand Up @@ -174,12 +173,19 @@ struct Segments {
/// that can be checked for equality. This way, two statuses,
/// collected at different times can be checked to determine whether their
/// gross, as opposed to fine, differences are significant.
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
/// In this implementation convert the status designations to strings which
/// match those strings that the kernel uses to identify the different states
#[derive(Clone, Copy, Debug, Eq, PartialEq, strum_macros::AsRefStr)]
pub enum ThinPoolStatusDigest {
#[strum(serialize = "Fail")]
Fail,
#[strum(serialize = "Error")]
Error,
#[strum(serialize = "rw")]
Good,
#[strum(serialize = "ro")]
ReadOnly,
#[strum(serialize = "out_of_data_space")]
OutOfSpace,
}

Expand All @@ -197,21 +203,6 @@ impl From<&ThinPoolStatus> for ThinPoolStatusDigest {
}
}

/// In this implementation convert the status designations to strings which
/// match those strings that the kernel uses to identify the different states
/// in the ioctl result.
impl fmt::Display for ThinPoolStatusDigest {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
ThinPoolStatusDigest::Good => write!(f, "rw"),
ThinPoolStatusDigest::ReadOnly => write!(f, "ro"),
ThinPoolStatusDigest::OutOfSpace => write!(f, "out_of_data_space"),
ThinPoolStatusDigest::Fail => write!(f, "Fail"),
ThinPoolStatusDigest::Error => write!(f, "Error"),
}
}
}

/// Calculate the room available for data that is not taken up by metadata.
fn room_for_data(usable_size: Sectors, meta_size: Sectors) -> Sectors {
Sectors(
Expand Down Expand Up @@ -790,26 +781,29 @@ impl ThinPool {

if current_status != new_status {
let current_status_str = current_status
.map(|x| x.to_string())
.unwrap_or_else(|| "none".to_string());
.as_ref()
.map(|x| x.as_ref())
.unwrap_or_else(|| "none");

if new_status != Some(ThinPoolStatusDigest::Good) {
warn!(
"Status of thinpool device with \"{}\" changed from \"{}\" to \"{}\"",
thin_pool_identifiers(&self.thin_pool),
current_status_str,
new_status
.map(|s| s.to_string())
.unwrap_or_else(|| "none".to_string()),
.as_ref()
.map(|s| s.as_ref())
.unwrap_or_else(|| "none"),
);
} else {
info!(
"Status of thinpool device with \"{}\" changed from \"{}\" to \"{}\"",
thin_pool_identifiers(&self.thin_pool),
current_status_str,
new_status
.map(|s| s.to_string())
.unwrap_or_else(|| "none".to_string()),
.as_ref()
.map(|s| s.as_ref())
.unwrap_or_else(|| "none"),
);
}
}
Expand Down

0 comments on commit 1f95306

Please sign in to comment.