[pbs-devel] [PATCH proxmox-backup 03/23] maintenance: add 'Unpplugged' maintenance type
Hannes Laimer
h.laimer at proxmox.com
Fri Sep 15 08:54:37 CEST 2023
Signed-off-by: Hannes Laimer <h.laimer at proxmox.com>
---
pbs-api-types/src/maintenance.rs | 31 ++++++++++++++++++++++++++++++-
1 file changed, 30 insertions(+), 1 deletion(-)
diff --git a/pbs-api-types/src/maintenance.rs b/pbs-api-types/src/maintenance.rs
index 1b03ca94..caab9eb5 100644
--- a/pbs-api-types/src/maintenance.rs
+++ b/pbs-api-types/src/maintenance.rs
@@ -38,7 +38,6 @@ pub enum Operation {
/// Maintenance type.
pub enum MaintenanceType {
// TODO:
- // - Add "unmounting" once we got pluggable datastores
// - Add "GarbageCollection" or "DeleteOnly" as type and track GC (or all deletes) as separate
// operation, so that one can enable a mode where nothing new can be added but stuff can be
// cleaned
@@ -48,6 +47,8 @@ pub enum MaintenanceType {
Offline,
/// The datastore is being deleted.
Delete,
+ /// The removable datastore is unplugged
+ Unplugged,
}
serde_plain::derive_display_from_serialize!(MaintenanceType);
serde_plain::derive_fromstr_from_deserialize!(MaintenanceType);
@@ -82,6 +83,10 @@ impl MaintenanceMode {
bail!("datastore is being deleted");
}
+ if self.ty == MaintenanceType::Unplugged {
+ bail!("datastore is not plugged in");
+ }
+
let message = percent_encoding::percent_decode_str(self.message.as_deref().unwrap_or(""))
.decode_utf8()
.unwrap_or(Cow::Borrowed(""));
@@ -98,3 +103,27 @@ impl MaintenanceMode {
Ok(())
}
}
+
+#[test]
+fn test_check() {
+ let ro_mode = MaintenanceMode::new(MaintenanceType::ReadOnly, None);
+ let offline_mode = MaintenanceMode::new(MaintenanceType::Offline, None);
+ let delete_mode = MaintenanceMode::new(MaintenanceType::Delete, None);
+ let unplugged_mode = MaintenanceMode::new(MaintenanceType::Unplugged, None);
+
+ assert!(ro_mode.check(Some(Operation::Lookup)).is_ok());
+ assert!(ro_mode.check(Some(Operation::Read)).is_ok());
+ assert!(ro_mode.check(Some(Operation::Write)).is_err());
+
+ assert!(offline_mode.check(Some(Operation::Lookup)).is_ok());
+ assert!(offline_mode.check(Some(Operation::Read)).is_err());
+ assert!(offline_mode.check(Some(Operation::Write)).is_err());
+
+ assert!(delete_mode.check(Some(Operation::Lookup)).is_err());
+ assert!(delete_mode.check(Some(Operation::Read)).is_err());
+ assert!(delete_mode.check(Some(Operation::Write)).is_err());
+
+ assert!(unplugged_mode.check(Some(Operation::Lookup)).is_err());
+ assert!(unplugged_mode.check(Some(Operation::Read)).is_err());
+ assert!(unplugged_mode.check(Some(Operation::Write)).is_err());
+}
--
2.39.2
More information about the pbs-devel
mailing list