pbs-datastore: use ConfigVersionCache for datastore
instead of relying on the content of some configs previously, we always read and parsed the config file, and only generated a new config object when the path or the 'verify-new' option changed. now, we increase the datastore generation on config save, and if that changed (or the last load is 1 minute in the past), we always generate a new object Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
This commit is contained in:
committed by
Dietmar Maurer
parent
9c96e5368a
commit
118deb4db8
@ -24,10 +24,12 @@ struct ConfigVersionCacheData {
|
||||
user_cache_generation: AtomicUsize,
|
||||
// Traffic control (traffic-control.cfg) generation/version.
|
||||
traffic_control_generation: AtomicUsize,
|
||||
// datastore (datastore.cfg) generation/version
|
||||
datastore_generation: AtomicUsize,
|
||||
|
||||
// Add further atomics here (and reduce padding size)
|
||||
|
||||
padding: [u8; 4096 - 3*8],
|
||||
padding: [u8; 4096 - 4*8],
|
||||
}
|
||||
|
||||
|
||||
@ -118,4 +120,18 @@ impl ConfigVersionCache {
|
||||
.fetch_add(1, Ordering::AcqRel);
|
||||
}
|
||||
|
||||
/// Returns the datastore generation number.
|
||||
pub fn datastore_generation(&self) -> usize {
|
||||
self.shmem
|
||||
.data()
|
||||
.datastore_generation
|
||||
.load(Ordering::Acquire)
|
||||
}
|
||||
|
||||
/// Increase the datastore generation number.
|
||||
pub fn increase_datastore_generation(&self) -> usize {
|
||||
self.shmem
|
||||
.data()
|
||||
.datastore_generation.fetch_add(1, Ordering::Acquire)
|
||||
}
|
||||
}
|
||||
|
@ -7,7 +7,7 @@ use proxmox_section_config::{SectionConfig, SectionConfigData, SectionConfigPlug
|
||||
|
||||
use pbs_api_types::{DataStoreConfig, DATASTORE_SCHEMA};
|
||||
|
||||
use crate::{open_backup_lockfile, replace_backup_config, BackupLockGuard};
|
||||
use crate::{open_backup_lockfile, replace_backup_config, BackupLockGuard, ConfigVersionCache};
|
||||
|
||||
lazy_static! {
|
||||
pub static ref CONFIG: SectionConfig = init();
|
||||
@ -46,7 +46,14 @@ pub fn config() -> Result<(SectionConfigData, [u8;32]), Error> {
|
||||
|
||||
pub fn save_config(config: &SectionConfigData) -> Result<(), Error> {
|
||||
let raw = CONFIG.write(DATASTORE_CFG_FILENAME, config)?;
|
||||
replace_backup_config(DATASTORE_CFG_FILENAME, raw.as_bytes())
|
||||
replace_backup_config(DATASTORE_CFG_FILENAME, raw.as_bytes())?;
|
||||
|
||||
// increase datastore version
|
||||
// We use this in pbs-datastore
|
||||
let version_cache = ConfigVersionCache::new()?;
|
||||
version_cache.increase_datastore_generation();
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
// shell completion helper
|
||||
|
Reference in New Issue
Block a user