#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum DwbDegradation {
OpenFailed,
WriteFailed,
FlushFailed,
}
impl std::fmt::Display for DwbDegradation {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
Self::OpenFailed => f.write_str("DWB could not be opened"),
Self::WriteFailed => f.write_str("DWB record write failed"),
Self::FlushFailed => f.write_str("DWB batch fsync failed"),
}
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum DwbProtection {
Active,
Off,
Degraded(DwbDegradation),
}
impl DwbProtection {
pub fn is_active(&self) -> bool {
matches!(self, Self::Active)
}
pub fn is_degraded(&self) -> bool {
matches!(self, Self::Degraded(_))
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum DwbSkipReason {
RecordTooLarge { size: usize, max: usize },
}
impl std::fmt::Display for DwbSkipReason {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
Self::RecordTooLarge { size, max } => {
write!(f, "record of {size} bytes exceeds the {max}-byte DWB slot")
}
}
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
#[must_use]
pub enum DwbMirror {
Mirrored,
Skipped(DwbSkipReason),
}