[pbs-devel] [PATCH proxmox-backup 04/11] reader: acquire shared flock on open snapshot
Stefan Reiter
s.reiter at proxmox.com
Wed Oct 14 14:16:32 CEST 2020
...to avoid it being forgotten or pruned while in use.
Update lock error message for deletions to be consistent.
Signed-off-by: Stefan Reiter <s.reiter at proxmox.com>
---
src/api2/reader.rs | 19 ++++++++++++++-----
src/backup/datastore.rs | 2 +-
2 files changed, 15 insertions(+), 6 deletions(-)
diff --git a/src/api2/reader.rs b/src/api2/reader.rs
index 4c870eda..8f47047e 100644
--- a/src/api2/reader.rs
+++ b/src/api2/reader.rs
@@ -17,6 +17,7 @@ use crate::tools;
use crate::config::acl::{PRIV_DATASTORE_READ, PRIV_DATASTORE_BACKUP};
use crate::config::cached_user_info::CachedUserInfo;
use crate::api2::helpers;
+use crate::tools::fs::lock_dir_noblock_shared;
mod environment;
use environment::*;
@@ -98,6 +99,11 @@ fn upgrade_to_backup_reader_protocol(
}
}
+ let _guard = lock_dir_noblock_shared(
+ &datastore.snapshot_path(&backup_dir),
+ "snapshot",
+ "locked by another operation")?;
+
let path = datastore.base_path();
//let files = BackupInfo::list_files(&path, &backup_dir)?;
@@ -146,11 +152,14 @@ fn upgrade_to_backup_reader_protocol(
use futures::future::Either;
futures::future::select(req_fut, abort_future)
- .map(|res| match res {
- Either::Left((Ok(res), _)) => Ok(res),
- Either::Left((Err(err), _)) => Err(err),
- Either::Right((Ok(res), _)) => Ok(res),
- Either::Right((Err(err), _)) => Err(err),
+ .map(move |res| {
+ let _guard = _guard;
+ match res {
+ Either::Left((Ok(res), _)) => Ok(res),
+ Either::Left((Err(err), _)) => Err(err),
+ Either::Right((Ok(res), _)) => Ok(res),
+ Either::Right((Err(err), _)) => Err(err),
+ }
})
.map_ok(move |_| env.log("reader finished successfully"))
})?;
diff --git a/src/backup/datastore.rs b/src/backup/datastore.rs
index 1f708293..a77c5f1d 100644
--- a/src/backup/datastore.rs
+++ b/src/backup/datastore.rs
@@ -227,7 +227,7 @@ impl DataStore {
let _guard;
if !force {
- _guard = lock_dir_noblock(&full_path, "snapshot", "possibly running or used as base")?;
+ _guard = lock_dir_noblock(&full_path, "snapshot", "possibly running or in use")?;
}
log::info!("removing backup snapshot {:?}", full_path);
--
2.20.1
More information about the pbs-devel
mailing list