maintenance: make is_offline more generic

... 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@proxmox.com>
This commit is contained in:
Hannes Laimer 2024-11-25 17:21:49 +01:00 committed by Thomas Lamprecht
parent 89c650b83e
commit 652b774eb0
2 changed files with 6 additions and 6 deletions

View File

@ -77,10 +77,9 @@ pub struct MaintenanceMode {
} }
impl MaintenanceMode { impl MaintenanceMode {
/// Used for deciding whether the datastore is cleared from the internal cache after the last /// Used for deciding whether the datastore is cleared from the internal cache
/// task finishes, so all open files are closed. pub fn clear_from_cache(&self) -> bool {
pub fn is_offline(&self) -> bool { self.ty == MaintenanceType::Offline || self.ty == MaintenanceType::Delete
self.ty == MaintenanceType::Offline
} }
pub fn check(&self, operation: Option<Operation>) -> Result<(), Error> { pub fn check(&self, operation: Option<Operation>) -> Result<(), Error> {

View File

@ -116,7 +116,8 @@ impl Drop for DataStore {
&& pbs_config::datastore::config() && pbs_config::datastore::config()
.and_then(|(s, _)| s.lookup::<DataStoreConfig>("datastore", self.name())) .and_then(|(s, _)| s.lookup::<DataStoreConfig>("datastore", self.name()))
.map_or(false, |c| { .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 { if remove_from_cache {
@ -216,7 +217,7 @@ impl DataStore {
let datastore: DataStoreConfig = config.lookup("datastore", name)?; let datastore: DataStoreConfig = config.lookup("datastore", name)?;
if datastore if datastore
.get_maintenance_mode() .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 // the datastore drop handler does the checking if tasks are running and clears the
// cache entry, so we just have to trigger it here // cache entry, so we just have to trigger it here