[pbs-devel] [PATCH proxmox-backup 2/3] datastore: cleanup open and load config only once
Stefan Reiter
s.reiter at proxmox.com
Mon Oct 19 16:45:22 CEST 2020
Force consumers to use the lookup_datastore method instead of
potentially opening a datastore twice, and pass the config we have
already loaded into open_with_path, removing the need for open(1).
Signed-off-by: Stefan Reiter <s.reiter at proxmox.com>
---
src/backup/datastore.rs | 18 ++++--------------
1 file changed, 4 insertions(+), 14 deletions(-)
diff --git a/src/backup/datastore.rs b/src/backup/datastore.rs
index 46039576..a856e2f4 100644
--- a/src/backup/datastore.rs
+++ b/src/backup/datastore.rs
@@ -46,17 +46,18 @@ impl DataStore {
let (config, _digest) = datastore::config()?;
let config: datastore::DataStoreConfig = config.lookup("datastore", name)?;
+ let path = PathBuf::from(&config.path);
let mut map = DATASTORE_MAP.lock().unwrap();
if let Some(datastore) = map.get(name) {
// Compare Config - if changed, create new Datastore object!
- if datastore.chunk_store.base == PathBuf::from(&config.path) {
+ if datastore.chunk_store.base == path {
return Ok(datastore.clone());
}
}
- let datastore = DataStore::open(name)?;
+ let datastore = DataStore::open_with_path(name, &path, config)?;
let datastore = Arc::new(datastore);
map.insert(name.to_string(), datastore.clone());
@@ -64,18 +65,7 @@ impl DataStore {
Ok(datastore)
}
- pub fn open(store_name: &str) -> Result<Self, Error> {
-
- let (config, _digest) = datastore::config()?;
- let (_, store_config) = config.sections.get(store_name)
- .ok_or(format_err!("no such datastore '{}'", store_name))?;
-
- let path = store_config["path"].as_str().unwrap();
-
- Self::open_with_path(store_name, Path::new(path))
- }
-
- pub fn open_with_path(store_name: &str, path: &Path) -> Result<Self, Error> {
+ fn open_with_path(store_name: &str, path: &Path, config: DataStoreConfig) -> Result<Self, Error> {
let chunk_store = ChunkStore::open(store_name, path)?;
let gc_status = GarbageCollectionStatus::default();
--
2.20.1
More information about the pbs-devel
mailing list