datastore: add check for maintenance in lookup

Signed-off-by: Hannes Laimer <h.laimer@proxmox.com>
This commit is contained in:
Hannes Laimer
2022-04-12 05:25:57 +00:00
committed by Thomas Lamprecht
parent 2a05c75ff1
commit e9d2fc9362
13 changed files with 86 additions and 54 deletions

View File

@ -19,7 +19,7 @@ use proxmox_sys::fs::{lock_dir_noblock, DirLockGuard};
use pbs_api_types::{
UPID, DataStoreConfig, Authid, GarbageCollectionStatus, HumanByte,
ChunkOrder, DatastoreTuning,
ChunkOrder, DatastoreTuning, Operation,
};
use pbs_config::{open_backup_lockfile, BackupLockGuard, ConfigVersionCache};
@ -68,11 +68,24 @@ pub struct DataStore {
}
impl DataStore {
pub fn lookup_datastore(name: &str) -> Result<Arc<DataStore>, Error> {
pub fn lookup_datastore(
name: &str,
operation: Option<Operation>,
) -> Result<Arc<DataStore>, Error> {
let version_cache = ConfigVersionCache::new()?;
let generation = version_cache.datastore_generation();
let now = proxmox_time::epoch_i64();
let (config, _digest) = pbs_config::datastore::config()?;
let config: DataStoreConfig = config.lookup("datastore", name)?;
let path = PathBuf::from(&config.path);
if let Some(maintenance_mode) = config.get_maintenance_mode() {
if let Err(error) = maintenance_mode.check(operation) {
bail!("datastore '{}' is in {}", name, error);
}
}
let mut map = DATASTORE_MAP.lock().unwrap();
let entry = map.get(name);
@ -82,10 +95,6 @@ impl DataStore {
}
}
let (config, _digest) = pbs_config::datastore::config()?;
let config: DataStoreConfig = config.lookup("datastore", name)?;
let path = PathBuf::from(&config.path);
let datastore = DataStore::open_with_path(name, &path, config, generation, now)?;
let datastore = Arc::new(datastore);

View File

@ -14,6 +14,7 @@ use crate::fixed_index::FixedIndexReader;
use crate::dynamic_index::DynamicIndexReader;
use crate::manifest::{archive_type, ArchiveType, CLIENT_LOG_BLOB_NAME, MANIFEST_BLOB_NAME};
use crate::DataStore;
use pbs_api_types::Operation;
/// Helper to access the contents of a datastore backup snapshot
///
@ -121,7 +122,10 @@ impl <'a, F: Fn(&[u8;32]) -> bool> Iterator for SnapshotChunkIterator<'a, F> {
};
let datastore =
DataStore::lookup_datastore(self.snapshot_reader.datastore_name())?;
DataStore::lookup_datastore(
self.snapshot_reader.datastore_name(),
Some(Operation::Read)
)?;
let order = datastore.get_chunks_in_order(&index, &self.skip_fn, |_| Ok(()))?;
self.current_index = Some((Arc::new(index), 0, order));