Skip to content

Commit

Permalink
Use strum for device names
Browse files Browse the repository at this point in the history
Signed-off-by: mulhern <[email protected]>
  • Loading branch information
mulkieran committed Nov 14, 2024
1 parent c55aab3 commit d34b83d
Showing 1 changed file with 11 additions and 33 deletions.
44 changes: 11 additions & 33 deletions src/engine/strat_engine/names.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

use std::fmt::{self, Display};

use strum_macros::{self};

use devicemapper::{DmNameBuf, DmUuidBuf};

pub use crate::engine::types::KeyDescription;
Expand Down Expand Up @@ -90,25 +92,18 @@ pub fn format_crypt_backstore_name(pool_uuid: &PoolUuid) -> DmNameBuf {
DmNameBuf::new(value).expect("FORMAT_VERSION display length < 73")
}

#[derive(Clone, Copy)]
#[derive(Clone, Copy, strum_macros::Display)]
pub enum FlexRole {
#[strum(serialize = "mdv")]
MetadataVolume,
#[strum(serialize = "thindata")]
ThinData,
#[strum(serialize = "thinmeta")]
ThinMeta,
#[strum(serialize = "thinmetaspare")]
ThinMetaSpare,
}

impl Display for FlexRole {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match *self {
FlexRole::MetadataVolume => write!(f, "mdv"),
FlexRole::ThinData => write!(f, "thindata"),
FlexRole::ThinMeta => write!(f, "thinmeta"),
FlexRole::ThinMetaSpare => write!(f, "thinmetaspare"),
}
}
}

#[derive(Clone, Copy)]
pub enum ThinRole {
Filesystem(FilesystemUuid),
Expand All @@ -122,21 +117,15 @@ impl Display for ThinRole {
}
}

#[derive(Clone, Copy)]
#[derive(Clone, Copy, strum_macros::Display)]
#[strum(serialize_all = "lowercase")]
pub enum ThinPoolRole {
Pool,
}

impl Display for ThinPoolRole {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match *self {
ThinPoolRole::Pool => write!(f, "pool"),
}
}
}

/// The various roles taken on by DM devices in the cache tier.
#[derive(Clone, Copy)]
#[derive(Clone, Copy, strum_macros::Display)]
#[strum(serialize_all = "lowercase")]
pub enum CacheRole {
/// The DM cache device, contains the other three devices.
Cache,
Expand All @@ -148,17 +137,6 @@ pub enum CacheRole {
OriginSub,
}

impl Display for CacheRole {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match *self {
CacheRole::Cache => write!(f, "cache"),
CacheRole::CacheSub => write!(f, "cachesub"),
CacheRole::MetaSub => write!(f, "metasub"),
CacheRole::OriginSub => write!(f, "originsub"),
}
}
}

/// Format a name & uuid for the flex layer.
///
/// Prerequisite: len(format!("{}", FORMAT_VERSION)
Expand Down

0 comments on commit d34b83d

Please sign in to comment.