From d34b83d4fad90520f0917a5387a639ea6f428c24 Mon Sep 17 00:00:00 2001 From: mulhern Date: Wed, 13 Nov 2024 20:29:33 -0500 Subject: [PATCH] Use strum for device names Signed-off-by: mulhern --- src/engine/strat_engine/names.rs | 44 ++++++++------------------------ 1 file changed, 11 insertions(+), 33 deletions(-) diff --git a/src/engine/strat_engine/names.rs b/src/engine/strat_engine/names.rs index 63e79447c5..ce3470b28f 100644 --- a/src/engine/strat_engine/names.rs +++ b/src/engine/strat_engine/names.rs @@ -6,6 +6,8 @@ use std::fmt::{self, Display}; +use strum_macros::{self}; + use devicemapper::{DmNameBuf, DmUuidBuf}; pub use crate::engine::types::KeyDescription; @@ -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), @@ -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, @@ -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)