[pbs-devel] [PATCH proxmox-backup v3 3/3] api: backup: avoid holding mutex and inline backup cleanup method
Christian Ebner
c.ebner at proxmox.com
Mon Sep 29 10:04:07 CEST 2025
The method to cleanup backups due to failure (or because a benchmark)
currently acquires a mutex guard before removing the backup directory.
Since the S3 backend however needs to execute code in async context,
it is not deadlock save to hold the guard. However, the guard was
only acquired to set the state to finished, which is however not
necessary since the request handling future is already executed to
completion, so this has no further effect.
Therefore, drop the mutex locking altoghether and inline the now
trivial simple function call to the respective callsides.
Signed-off-by: Christian Ebner <c.ebner at proxmox.com>
---
changes since version 2:
- not present in previous version
src/api2/backup/environment.rs | 14 --------------
src/api2/backup/mod.rs | 24 +++++++++++++++++++++---
2 files changed, 21 insertions(+), 17 deletions(-)
diff --git a/src/api2/backup/environment.rs b/src/api2/backup/environment.rs
index de6ce3c89..ace305d7e 100644
--- a/src/api2/backup/environment.rs
+++ b/src/api2/backup/environment.rs
@@ -833,20 +833,6 @@ impl BackupEnvironment {
state.finished == BackupState::Finished
}
- /// Remove complete backup
- pub fn remove_backup(&self) -> Result<(), Error> {
- let mut state = self.state.lock().unwrap();
- state.finished = BackupState::Finished;
-
- self.datastore.remove_backup_dir(
- self.backup_dir.backup_ns(),
- self.backup_dir.as_ref(),
- true,
- )?;
-
- Ok(())
- }
-
fn s3_upload_index(&self, s3_client: &S3Client, name: &str) -> Result<(), Error> {
let object_key =
pbs_datastore::s3::object_key_from_path(&self.backup_dir.relative_path(), name)
diff --git a/src/api2/backup/mod.rs b/src/api2/backup/mod.rs
index ae61ff697..8a076a2b0 100644
--- a/src/api2/backup/mod.rs
+++ b/src/api2/backup/mod.rs
@@ -282,7 +282,13 @@ fn upgrade_to_backup_protocol(
};
if benchmark {
env.log("benchmark finished successfully");
- proxmox_async::runtime::block_in_place(|| env.remove_backup())?;
+ proxmox_async::runtime::block_in_place(|| {
+ env.datastore.remove_backup_dir(
+ env.backup_dir.backup_ns(),
+ env.backup_dir.as_ref(),
+ true,
+ )
+ })?;
return Ok(());
}
@@ -310,13 +316,25 @@ fn upgrade_to_backup_protocol(
(Ok(_), Err(err)) => {
env.log(format!("backup ended and finish failed: {}", err));
env.log("removing unfinished backup");
- proxmox_async::runtime::block_in_place(|| env.remove_backup())?;
+ proxmox_async::runtime::block_in_place(|| {
+ env.datastore.remove_backup_dir(
+ env.backup_dir.backup_ns(),
+ env.backup_dir.as_ref(),
+ true,
+ )
+ })?;
Err(err)
}
(Err(err), Err(_)) => {
env.log(format!("backup failed: {}", err));
env.log("removing failed backup");
- proxmox_async::runtime::block_in_place(|| env.remove_backup())?;
+ proxmox_async::runtime::block_in_place(|| {
+ env.datastore.remove_backup_dir(
+ env.backup_dir.backup_ns(),
+ env.backup_dir.as_ref(),
+ true,
+ )
+ })?;
Err(err)
}
}
--
2.47.3
More information about the pbs-devel
mailing list