[pbs-devel] [PATCH proxmox-backup v14 02/25] maintenance: make is_offline more generic

Hannes Laimer h.laimer at proxmox.com
Fri Nov 22 15:46:49 CET 2024


... and add MaintenanceType::Delete to it. We also want to clear any
cach entries if we are deleting the datastore, not just if it is marked
as offline.

Signed-off-by: Hannes Laimer <h.laimer at proxmox.com>
---
* new in v14

 pbs-api-types/src/maintenance.rs | 7 +++----
 pbs-datastore/src/datastore.rs   | 5 +++--
 2 files changed, 6 insertions(+), 6 deletions(-)

diff --git a/pbs-api-types/src/maintenance.rs b/pbs-api-types/src/maintenance.rs
index 1e3413dca..a7b8b078d 100644
--- a/pbs-api-types/src/maintenance.rs
+++ b/pbs-api-types/src/maintenance.rs
@@ -77,10 +77,9 @@ pub struct MaintenanceMode {
 }
 
 impl MaintenanceMode {
-    /// Used for deciding whether the datastore is cleared from the internal cache after the last
-    /// task finishes, so all open files are closed.
-    pub fn is_offline(&self) -> bool {
-        self.ty == MaintenanceType::Offline
+    /// Used for deciding whether the datastore is cleared from the internal cache
+    pub fn clear_from_cache(&self) -> bool {
+        self.ty == MaintenanceType::Offline || self.ty == MaintenanceType::Delete
     }
 
     pub fn check(&self, operation: Option<Operation>) -> Result<(), Error> {
diff --git a/pbs-datastore/src/datastore.rs b/pbs-datastore/src/datastore.rs
index 2755fed8c..2bf2b8437 100644
--- a/pbs-datastore/src/datastore.rs
+++ b/pbs-datastore/src/datastore.rs
@@ -116,7 +116,8 @@ impl Drop for DataStore {
                 && pbs_config::datastore::config()
                     .and_then(|(s, _)| s.lookup::<DataStoreConfig>("datastore", self.name()))
                     .map_or(false, |c| {
-                        c.get_maintenance_mode().map_or(false, |m| m.is_offline())
+                        c.get_maintenance_mode()
+                            .map_or(false, |m| m.clear_from_cache())
                     });
 
             if remove_from_cache {
@@ -216,7 +217,7 @@ impl DataStore {
         let datastore: DataStoreConfig = config.lookup("datastore", name)?;
         if datastore
             .get_maintenance_mode()
-            .map_or(false, |m| m.is_offline())
+            .map_or(false, |m| m.clear_from_cache())
         {
             // the datastore drop handler does the checking if tasks are running and clears the
             // cache entry, so we just have to trigger it here
-- 
2.39.5





More information about the pbs-devel mailing list